June 28, 2012 at 7:50 am
I know your question was about getting these results into multiple result sets, which is a bit odd but I think you have been shown how to do that now.
The reason I am posting is because you have a number of subselects using top 1 and NONE of them have an order by. That means you don't know which row sql will select. You should figure out what the logic is for the "top row" and add the order by to every one of those subqueries.
_______________________________________________________________
Need help? Help us help you.
Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.
Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.
Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/
June 28, 2012 at 1:05 pm
dwain.c (6/27/2012)
Wouldn't another option to be create a VIEW (or CTE) in front of each of the 3 statements that display results with a ROW_NUMBER() and then process in a loop rows 1-10, 11-20, 21-30, etc.?
Sure, but you've just added in the overhead of a windows function as well as the original request was to go 1, 2, 3, not 1-10, 11-20... Cursor is actually perfect for the desired result.
Never stop learning, even if it hurts. Ego bruises are practically mandatory as you learn unless you've never risked enough to make a mistake.
For better assistance in answering your questions[/url] | Forum Netiquette
For index/tuning help, follow these directions.[/url] |Tally Tables[/url]
Twitter: @AnyWayDBA
Viewing 2 posts - 16 through 16 (of 16 total)
You must be logged in to reply to this topic. Login to reply