Nothing revolutionary here, I just recently tried to use a SQL CASE statement as part of an SQL UPDATE statement.
I had never tried this before and I am quite happy that it works.
I used to have conditions around queries all the time. Tell me how will you write a sql where you have to update one field only if its null where as other fields should be updated at the same time with no condition. RTRMNT_FG --UPDATE ONLY WHEN ITS NULL END , DT_OF_RTRMNT = SOURCE.
Now that I know what you mean, I can totally relate. INESRTEND IFWhen I switched to My SQL, I had to break apart all kinds of queries. UPDATE TABLESETA (only if its null)= B.a, X= B.x, Y = B.y @ABHAY, NEVERMIND I GOT IT, btw i am using MERGE i hope the same logic can be applied for simple update aswell.
I should have guessed you could since the FROM statement is there and joining would making sense if you need to bring data from other locations.
I learned how to use it because I needed to move data from one database to another (QA to DEV).
Otherwise, you'd probably want to use tsql or a stored proc. Another nice technique that I have found invaluable on occasion is using a join in an update statement.
I don't know if something like this works on My SQL but on SQL Server you can do something like the following UPDATE p SET p.col1 = p.col1 q.other Col FROM table1 AS p join table2 AS q ON p.fk_table2_pk = WHERE q.filter Column = 'something' @Ben/John, I had just learned you could do joins in an UPDATE SQL statement early last month.
Microsoft is conducting an online survey to understand your opinion of the Msdn Web site.
If you choose to participate, the online survey will be presented to you when you leave the Msdn Web site.
It's easy to get lost in SQL but it can really do some neat stuff.