?
Solved

using an array or temp table for a stored procedure in mssql

Posted on 2014-12-10
2
Medium Priority
?
118 Views
Last Modified: 2014-12-10
I have the following declaration in a stored procedure:

DECLARE @EndDate AS DATETIME
SET @EndDate = CAST (@PeriodEnd AS DATE)
SET @EndDate = dbo.fn_LocalTimeToUTC(@EndDate)

I would like to create an array or table that lists all the dates from 1/1/2013 to date:

('01/01/2013', '01/02/2013',.....'12/10/2014')

and use it as the @PeriodEnd date to cycle thru as my stored procedure creates one row of data for each date input.

Thanks in advance for any help.
0
Comment
Question by:plainwrapname
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 57

Accepted Solution

by:
HainKurt earned 2000 total points
ID: 40492038
create a loop and call your sp inside loop

set @MyDate = "2013-01-01";
while  @MyDate < @endDate
Begin
  MySP @MyDate;
  set @MyDate = @MyDate +1;
End

Open in new window

;
0
 
LVL 27

Expert Comment

by:Sinisa Vuk
ID: 40492370
Better pass start and end date in stored procedure, set them in your query and group all by date part:

select datefield1 from table1 where datefield1>=@StartDate and datefield1<=@EndDate
group by Date(datefield1)

Open in new window

0

Featured Post

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Why is this different from all of the other step by step guides?  Because I make a living as a DBA and not as a writer and I lived through this experience. Defining the name: When I talk to people they say different names on this subject stuff l…
The Delta outage: 650 cancelled flights, more than 1200 delayed flights, thousands of frustrated customers, tens of millions of dollars in damages – plus untold reputational damage to one of the world’s most trusted airlines. All due to a catastroph…
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
Via a live example combined with referencing Books Online, show some of the information that can be extracted from the Catalog Views in SQL Server.

800 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question