开发者

How can I take values From a table which is output of a function in a stored procedure

开发者 https://www.devze.com 2023-01-25 01:33 出处:网络
This is a statement inside a stored procedure which gives a table output which contains date dt: SELECT [Dt]

This is a statement inside a stored procedure which gives a table output which contains date dt:

SELECT [Dt] 
  FROM dbo.fnGetDatesforWeekDays(@dafromDate, @datoDate, @WKDAYS) AS DAT

How can I take those date values one by one开发者_StackOverflow社区?


If you need to process them one by one you'll need to use a cursor and loop through the cursor:

DECLARE @Dt DATETIME

DECLARE date_cursor CURSOR
FOR
SELECT [Dt]  
  FROM dbo.fnGetDatesforWeekDays(@dafromDate, @datoDate, @WKDAYS) AS DAT 

OPEN date_cursor

FETCH NEXT FROM date_cursor INTO @Dt

WHILE @@FETCH_STATUS <> -1
BEGIN
--do your processing here

FETCH NEXT FROM date_cursor INTO @Dt

END

CLOSE date_cursor

DEALLOCATE date_cursor

Just do whatever you want to do with each of those dates where the comment is and you're good to go.


Yes, you can (cursor, loop, ..) .. but you shouldn't. Please post what are you trying to accomplish and most likely there is a better, set based solution.

0

精彩评论

暂无评论...
验证码 换一张
取 消