Skip to Content
avatar image
Former Member

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

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

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

4 Answers

  • Best Answer
    avatar image
    Former Member
    Feb 17, 2010 at 01:38 PM

    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

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Feb 17, 2010 at 06:51 PM

    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

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Jan 31, 2010 at 11:33 AM

    Hi Russell Clayton,

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

    Regards,

    Madhan.

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Mar 09, 2010 at 12:13 AM

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

    Add comment
    10|10000 characters needed characters exceeded