cancel
Showing results for 
Search instead for 
Did you mean: 

Declare @StartDate/@EndDate in SQL View; cannot save (for use w/ ODBC)

Former Member
0 Kudos

I have searched all over to find out how, in proper syntax, to code a date range-specific query that works just fine in SAP, but cannot be saved in a SQL view (to in turn be linked to an Excel spreadsheet). An answer that links me to the proper thread could be nice... if it truly explains how to begin and end a functioning basic query with a user supplied date range while working in Excel.

The error I receive when starting my view with "declare" is "the Declare cursor SQL construct or statement is not supported."

Here's the beginning and abbreviated end of code from a query that works just fine without the date clause in SQL view:

DECLARE @StartDate DateTime

DECLARE @EndDate DateTime

SET @StartDate = [%0]

SET @EndDate = [%1]

SELECT .........

FROM .........

WHERE (T0.DocDueDate >= @StartDate AND T0.DocDueDate <= @EndDate) AND ......

Thank you in advance!

Russell

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi Russell.

You don't need to use Declare.

Try this

SELECT .........

FROM .........

WHERE (T0.DocDueDate >= '[[%0]]' AND T0.DocDueDate <= '[[%1]]') AND ......

Antonio Ramos

Edited by: Antonio Ramos on Feb 17, 2010 2:38 PM

Answers (3)

Answers (3)

Former Member
0 Kudos

I will try a stored procedure / another way. Thank you -

Former Member
0 Kudos

Russel, you can't declare variables to a SQL View.

What you can do is simply create the view without filtering the date, and the on your Select filter by the intervals you want.

Another option would be to create a Stored Procedure. You can use variables there.

Hope it helps.

Danilo Souza

Former Member
0 Kudos

Hi Russell Clayton,

Try to run your query to Query Generator and Save as Query Manager.

Regards,

Madhan.