Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1007741
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T08:39:50+00:00 2026-05-16T08:39:50+00:00

I´m trying to create a VIEW in SQL Server 2005. The SQL code is

  • 0

I´m trying to create a VIEW in SQL Server 2005.

The SQL code is working as such (I´m using it in VS2008), but in SQL Server I´m unable to save it, as error message “Declare the scalar variable @StartDate” and “Declare the scalar variable @EndDate” pops up.

Here is the code:

WITH Calendar AS (SELECT     CAST(@StartDate AS datetime) AS Date
     UNION ALL
     SELECT     DATEADD(d, 1, Date) AS Expr1
     FROM         Calendar AS Calendar_1
     WHERE     (DATEADD(d, 1, Date) < @EndDate))
    SELECT     C.Date, C2.Country, COALESCE (SUM(R.[Amount of people per day needed]), 0) AS [Allocated testers]
     FROM         Calendar AS C CROSS JOIN
                            dbo.Country AS C2 LEFT OUTER JOIN
                            dbo.Requests AS R ON C.Date BETWEEN R.[Start date] AND R.[End date] AND R.CountryID = C2.CountryID
     GROUP BY C.Date, C2.Country

And my question is of course – exactly how should I declare them?

I tried to put the following first in the code:

DECLARE @StartDate smalldatetime
DECLARE @EndDate smalldatetime

But that didn´t do the trick, just as I expected – it only gave me another pop-up message:

“The Declare cursor SQL construct or statement is not supported.”

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T08:39:51+00:00Added an answer on May 16, 2026 at 8:39 am

    As Alex K has mentioned, you should write it as a inline table valued function. Here is the article that describes about it.

    In short, syntax would be something like

    CREATE FUNCTION dbo.GetForPeriod
        ( @StartDate datetime, @EndDate datetime) 
    RETURNS TABLE 
    RETURN 
       SELECT  [[ your column list ]]
       FROM    [[ table list]
       WHERE   [[some column] BETWEEN @StartDate AND @EndDate
    

    You can have one select query (however complex, can use CTE). And then you will use it as

    SELECT * FROM dbo.GetForPeriod('1-Jan-2010', '31-Jan-2010')
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am learning how to create view using SQL server. I am trying to
I am using SQL Server 2005 SP3 Standard Edition but cannot create an indexed
I'm trying to create table from view from remote server (calling procedure UPDATE_PROC), like
I am very new to SQL Server Stored Procedures, I am trying to create
I'm trying to change the size of a column in sql server using: ALTER
Using FNH w/ SQL Server 2008, I'm trying to add a Version as a
Database: SQL Server 2005 I'm using a function that creates a comma separated list
I'm trying to script an MS SQL Server 2005 database to a single file.
I am trying to get running totals in my View in SQL Server 2008
In SQL Server 2005, I'm trying to use a User Defined Function in a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.