Solved

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

Posted on 2014-12-10
2
111 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
Comment Utility
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 25

Expert Comment

by:Sinisa Vuk
Comment Utility
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

In this article—a derivative of my DaytaBase.org blog post (http://daytabase.org/2011/06/18/what-week-is-it/)—I will explore a few different perspectives on which week today's date falls within using Microsoft SQL Server. First, to frame this stu…
Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
Using examples as well as descriptions, and references to Books Online, show the different Recovery Models available in SQL Server and explain, as well as show how full, differential and transaction log backups are performed
Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…

744 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

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now