Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
jefals
Starting Member
8 Posts |
Posted - 2011-04-26 : 22:56:45
|
| Hello;I'm going thru "Beginning SQL Server 2008 for Developers"..It's probably not one of the best intro books, and there are many areas where the explanations for what the author is doing is either weak or non-existent....Here's a stored procedure from the book, and the line I'm having problem with is highlighted. The procedure is to demonstrate several things -- CASE, JOIN, WHILE, etc..and the context is getting a running total of someone's balance between two dates. My only problem is I don't know what that SELECT line I've highlighted is doing; is it setting the 3 variables? The author comments that he is using @STILLCALC as a test for the WHILE loop, but that it could be any variable as he is using the CONTINUE and BREAK statements to determine when to exit the loop.Thanks,Jeff Screate procedure customerdetails.apf_custmovement @custid bigint,@fromdate datetime, @todate datetimeas begindeclare @runningbal money, @stillcalc bit,@lasttran bigintselect @stillcalc = 1,@lasttran=0,@runningbal=0while @stillcalc=1beginselect top 1 @runningbal=@runningbal + case when tt.credittype = 1 then t.amount else t.amount * -1 end, @lasttran = t.transactionidfrom CustomerDetails.Customers cjoin transactiondetails.transactions t on t.customerid=c.customeridjoin transactiondetails.transactiontypes tt on tt.transactiontypeid=t.transactiontype where t.transactionid > @lasttran and tt.affectcashbalance = 1 and dateentered between @fromdate and @todate order by dateenteredif @@rowcount > 0 continue else breakendselect @runningbal as 'End Balance'endgo |
|
|
robvolk
Most Valuable Yak
15732 Posts |
Posted - 2011-04-26 : 23:12:27
|
quote: is it setting the 3 variables?
Yes. SELECT can assign values, like SET, except SET only assigns to one variable at a time, while SELECT can do multiple variables at once. |
 |
|
|
jefals
Starting Member
8 Posts |
Posted - 2011-04-27 : 02:07:48
|
| got it. Thanks Rob |
 |
|
|
|
|
|
|
|