Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
SQL Server Select Processing order?
Message
 
 
General information
Forum:
Microsoft SQL Server
Category:
SQL syntax
Environment versions
SQL Server:
SQL Server 2014
Application:
Web
Miscellaneous
Thread ID:
01616334
Message ID:
01616345
Views:
33
>>>
>>>can't you just order by Date ?
>>
>>The order by Date will give the resulting order by Date. But I need to process (the code not shown in my example) the records during the SQL Select. And I want them to be processed in certain order.
>
>Hi, Dmitry,
>
>I think you might want to post your code that's doing the processing, or at least give an explanation for that that processing is doing.
>
>If for instance, you need to calculate a rolling average or cumulative sum where the order of rows is important for the aggregation/accumulation, then there are several techniques that can be done (self join, subquery, or even the new analytic functions in sql 2012)

I will explain in words since I have a problem creating a sample SQL Select.
Say, I have TableA (structure as of example in my initial message).
Say, I have a TableB (a little different structure than TableA but very similar, for the purpose of this example).
I want to process records in TableA and, for each record in TableA, add a record in TableB. As I process I want to Count the total of field Quantity and when the total value of processed records Quantity field is greater or equal to some variable value, stop adding records to TableB.
And as I process records in TableA and adding records to TableB, I want to process "older" records First and then newer. So if the Total Quantity value (paragraph above) hits the "limit", the newer records of TableA are not processed.

Does it make any sense? :)
"The creative process is nothing but a series of crises." Isaac Bashevis Singer
"My experience is that as soon as people are old enough to know better, they don't know anything at all." Oscar Wilde
"If a nation values anything more than freedom, it will lose its freedom; and the irony of it is that if it is comfort or money that it values more, it will lose that too." W.Somerset Maugham
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform