Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
reidkell
Starting Member
16 Posts |
Posted - 2013-09-23 : 17:10:28
|
Hi, all. This is probably very simple, but is escaping me. Here is a greatly simplified version of a query of mine:SELECT HostName, IPAddress, SerialNum, Mfg FROM tblMasterOut of 5K rows, there are 100 with missing serial numbers. I have the missing serial numbers in another table (obtained by another feed), but don't know how to write a single TSQL statement to fill those 100 missing serial numbers. Any help appreciated. |
|
tkizer
Almighty SQL Goddess
38200 Posts |
Posted - 2013-09-23 : 17:11:59
|
update mset SerialNum = t.SerialNumfrom tblMaster mjoin SomeOtherTable ton m.HostName = t.HostName --or whatever your linking column iswhere m.SerialNum is nullTara KizerSQL Server MVP since 2007http://weblogs.sqlteam.com/tarad/ |
|
|
reidkell
Starting Member
16 Posts |
Posted - 2013-09-25 : 20:41:42
|
Thank you. What's escaping me is a means of accomplishing this from a SELECT statement, sans an UPDATE. Is this possible? |
|
|
LoztInSpace
Aged Yak Warrior
940 Posts |
Posted - 2013-09-26 : 02:27:48
|
SELECT HostName, IPAddress, SerialNum, Mfg FROM tblMaster UNION ALLSELECT HostName, IPAddress, SerialNum, Mfg FROM OtherTable |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2013-09-26 : 02:53:58
|
Using Tara's example.SELECT m.HostName, m.IPAddress, COALESCE(m.SerialNum, t.SerialNum) AS SerialNum, m.MfgFROM dbo.tblMaster AS mLEFT JOIN dbo.SomeOtherTable AS t ON t.HostName = m.HostName --or whatever your linking column is Microsoft SQL Server MVP, MCT, MCSE, MCSA, MCP, MCITP, MCTS, MCDBA |
|
|
reidkell
Starting Member
16 Posts |
Posted - 2013-09-26 : 12:21:41
|
Yes!! COALESCE did it. I had not used that before. Many thanks!! |
|
|
|
|
|
|
|