29 September 2008

SQL Update

Try as i might, i NEVER remember how to do this:

UPDATE table1
SET snakesOnAPlane = t2.data
FROM table1 t1
JOIN table2 t2 ON t2.row1 = t1.row1
WHERE t1.row3 = 'helloWorld'

22 September 2008

SQL Transaction

bit like in cfmx here's a useful bit of t-sql / sql for rolling back on error.

BEGIN TRAN
insert into ()--....sql goes here

IF @@ERROR <> 0
BEGIN
ROLLBACK TRAN
END
COMMIT TRAN

It's not perfect but it seems to work...sometimes....if the wind is blowing north, and it's a wednesday.