March 2008
Sun Mon Tue Wed Thu Fri Sat
            1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31          
Search

 
Catagories
Archives
Recent Entries
Links
RSS

April 21, 2005

update with var assignment

Catagory: sql server · This Entry · Comment(0) · eMail entry · Google
sql server

here's an example of how you can perform a variable assignment in an sql update statement. each row processed by the update *also* performs the assignment.

the key is to use this syntax...

SET @x = MyIntegerColumn = @x + 1

this example just increments a value - so each row updated gets a higher value (most cases you would use an index for such a task).

read more...
 
Posted by 7hz at 03:10 PM | Comments (0)

pivot row into a comma delimited list

Catagory: sql server · This Entry · Comment(1) · eMail entry · Google
sql server

ok, whoa, just picked this one up. usually variable assignment from a select statement is thought of as returning one final *single* value (whatever that happens to be).

if instead you perform some logical operations a variable in the meantime you can also continuously calculate and update a variable based on each subsequent row returned.

read more...
 
Posted by 7hz at 02:31 PM | Comments (1)