Solved

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

Posted on 2014-12-10
2
114 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
2 Comments
 
LVL 51

Accepted Solution

by:
HainKurt earned 500 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 26

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

Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

Question has a verified solution.

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

Everyone has problem when going to load data into Data warehouse (EDW). They all need to confirm that data quality is good but they don't no how to proceed. Microsoft has provided new task within SSIS 2008 called "Data Profiler Task". It solve th…
I have a large data set and a SSIS package. How can I load this file in multi threading?
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.

839 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