Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Price is inversly proportional to ease of use
Message
From
07/02/2003 00:41:34
 
 
General information
Forum:
Microsoft SQL Server
Category:
Stored procedures, Triggers, UDFs
Miscellaneous
Thread ID:
00750165
Message ID:
00750462
Views:
13
In the code I actually use the alias 'REQQTR1' etc but I didn't know rollup was a keyword. Michael, I am going to try and impliment your shorter solution tomorrow. Is there a way to get the job done with a single SELECT for my 13 or so sum fields? Or is the method here the way. I anticipate this table will have between 300,000 to 600,000 records on upper end equipment. So is the multiple SELECT a bad hit?
UPDATE foo
SET myField = (SELECT SUM(myField) FROM foo WHERE ikey LIKE '1%' AND ikey != '100')
SET myField1 = (SELECT SUM(myField1) FROM foo WHERE ikey LIKE '1%' AND ikey != '100')
SET myField2 = (SELECT SUM(myField2) FROM foo WHERE ikey LIKE '1%' AND ikey != '100')
-- ETC 
WHERE iKey='100'
My thanks again for your help,
Joe

>It doesn't work because Rollup is an alias for a column and the results were returned to the client. To get the behavior using your example, you'd probably do something like this:
>
>
>-- Roll up the values
>DECLARE @rollup int
>select
>    @rollup = sum(MyField)
>from foo
>    where left(IKey,1) = '1'
>
> -- insert the rolled up values
> update foo
>     set
>        MyField = @RollUp
>where IKey = '100'
>
>
>Now, a better solution would be to stay in the set based operations. So, you could also write:
>
>
>UPDATE foo
>SET myField = (SELECT SUM(myField) FROM foo WHERE ikey LIKE '1%' AND ikey != '100')
>WHERE iKey='100'
>
>
>-Mike
>
>>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
[SNIP]
~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

Previous
Next
Reply
Map
View

Click here to load this message in the networking platform