Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Enhancement actual select to update all rows
Message
 
 
To
03/01/2013 10:48:51
General information
Forum:
Microsoft SQL Server
Category:
SQL syntax
Environment versions
SQL Server:
SQL Server 2008
Application:
Web
Miscellaneous
Thread ID:
01561223
Message ID:
01561285
Views:
31
>>Change UNION to UNION ALL and if you're using SQL 2008 or up I suggest to switch to MERGE syntax instead of proprietary UPDATE-SQL.
>
>The UNION ALL does not change anything. I do not know about the MERGE syntax. Could you elaborate more on this?

I know it will not change the output, but UNION without ALL does distinct select and in your case you don't want a distinct. In other words, you don't want extra work which is done with DISTINCT.

Merge syntax is documented well in BOL, for your case it will be
MERGE myTable as target
USING (query with UNION ALL) as source
ON target.ID = source.ID
WHEN MATCHED 
   THEN UPDATE
    SET Totals = Source.Totals
If it's not broken, fix it until it is.


My Blog
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform