Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Price is inversly proportional to ease of use
Message
From
06/02/2003 15:48:38
 
 
To
All
General information
Forum:
Microsoft SQL Server
Category:
Stored procedures, Triggers, UDFs
Title:
Price is inversly proportional to ease of use
Miscellaneous
Thread ID:
00750165
Message ID:
00750165
Views:
61
Why does this not Work? I am certain I have oversimplified the mighty T-SQL language. I have some records that get a rollup value based on the records type. Much like an invoice total, except I have to store the rollup for whatever reason. There are about 13 fields to rollup so I have reduced it to one for readability. An overly simplified recordset might look like this;
record #1 IKEY = 101 | MyField = 10 | rTYPE = Item
record #2 IKEY = 102 | MyField = 20 | rTYPE = Item
record #3 IKEY = 103 | MyField = 30 | rTYPE = Item
record #4 IKEY = 100 | MyField = 00 | rTYPE = Rollup
record #5 IKEY = 201 | MyField = 18 | rTYPE = Item
record #6 IKEY = 202 | MyField = 24 | rTYPE = Item
Where the total that should be written to MyField for record IKEY 100 should be 60. I have pulled out all but the meat of the query here:
-- Roll up the values
select 
    sum(MyField) as RollUp
from foo 
    where left(IKey,1) = '1'

 -- insert the rolled up values
 update foo
     set 
        MyField = RollUp
where IKey = '100'
My humble thanks in advance,
~Joe Johnston USA

"If ye love wealth better than liberty, the tranquility of servitude better than the animated contest of freedom, go home from us in peace. We ask not your counsel or arms. Crouch down and lick the hands which feed you. May your chains set lightly upon you, and may posterity forget that ye were our countrymen."
~Samuel Adams

Next
Reply
Map
View

Click here to load this message in the networking platform