Solved

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

Posted on 2014-12-10
2
113 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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
SQL Syntax 5 35
SSRS - How do I get a year value to display based on the current month? 8 40
export sql results to csv 6 35
SQL Update trigger 5 16
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…
Slowly Changing Dimension Transformation component in data task flow is very useful for us to manage and control how data changes in SSIS.
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, show how to shrink a transaction log file down to a reasonable size.

776 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