user defined parameters within views

  • I wonder if anyone can help.

    I've created a view in SQL 2000 which queries a Sales table.

    The query looks like this

    Select

    Sales.SalDept

    Sum(SalesValue)

    From

    Sales

    Where SalWeekNo Between 26 AND 49

    Where I'm struggling, and my question is, next week when i run view the result of the query i want to change the start weekNo and end WeekNo to something other than 26 and 49.

    in MSACCESS in can do this easily by writing the parameters in square brackets ie Between [Enter start week number] and [Enter End Week Number]

    Does anyone know how to achieve the same thing in SQL2000? I need the end user to be able to select which weeks they want the query to report on.

     

    Thanks

     

    APB

  • This functionality does not exist within SQL Views.  However, you can research user-defined TABLE functions where you can do this 🙂

     



    Good Hunting!

    AJ Ahrens


    webmaster@kritter.net

  • You could use a stored proc

     

    CREATE PROCEDURE rpDeptSalesValue @StartWeek INT, @EndWeek INT

    AS

    SELECT

       Sales.SalDept

       Sum(SalesValue)

    FROM

       Sales

    WHERE

        SalWeekNo Between @StartWeek AND @EndWeek

    GROP BY Sales.SalDept

     

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply