I have a table Links with fields code (string) and link (string). Some of the links are NULL, so I need to update those values based a correct full mapping in excel (sheet has the same fields). Now, this should be easy, and it is on my local machine, because I can just import the excel sheet into SQL Server. But, in the production servers, I am not able/allowed to add to the existing tables, only to run queries. I have been requested to get SQL to produce a query that would do the same job as the update/merge I am describing--without adding the source table.
Wondering if there is any setting or command that would allow me to access the end-product updates (containing the string form of code and link) that run when I run the update query on my local machine with the other table. Using SQL Server/SSMS 2019.
| code | link |
| ------------ | ------------ |
| PM.23.fd | http://... |
| PM.25.df | NULL |
code | link |
---|---|
PM.23.fd | http://... |
PM.25.df | http://... |
1条答案
按热度按时间zujrkrfu1#
You can create a "pseudotable" in form of
values('pm.25.df', 'http://xyz'),('other', 'http://abc')
and then ask the guy to do a merge on the pseudo table in form of:I use merge because you mentioned it, but if you only interested in update, you can just change the query:
This only updates codes where link is null.
If you have more than 1000 rows, then values will not work, then you generate a temp table that you insert into