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.

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 matching all nulls agianst another table

Author  Topic 

jszulc
Yak Posting Veteran

66 Posts

Posted - 2012-03-02 : 08:00:05
How can I build a query to show all records from vm_sites with site column populated based on matches from Assets table? The number of records in vm_Sites should be still the same after the match, just trying to match all nulls in vm_Sites with Assets table.

Table 1
SELECT Sname,site,volsize from vm_Sites


Table 2
SELECT Sname,site from Assets

Thank you

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-03-02 : 12:33:00
you cant match NULLs as NULL cant be equated to NULL under default conditions. NULL means its unknown value and its not a value by itself. So comparison between two NULL doesnt even make sense

if for matching actual values you can use below logic

SELECT *
FROM vm_sites v
WHERE EXISTS (SELECT 1 FROM Assests WHERE site = v.site


and if you really think all NULL in your case have to be treated equivalent use ISNULL or COALESCE functions to change them to valid default value before comparison

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -