SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Check for null values not working
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

yellowman
Starting Member

USA
25 Posts

Posted - 12/03/2012 :  09:20:20  Show Profile  Reply with Quote
I have the oddest problem when trying to look for empty/null values in a table. For some reason it doesn't pick them up as expected.

The script is suppossed to return the database name if the schema version table is empty, but instead it doesn't return anything. Any ideas?

SELECT @command = 'USE ' +@DB_Name+ ' 
                   SELECT '+ ''''+@DB_Name+ '''' +' as DB_Name, version_number
                   FROM ' +@DB_Name + '.CQ_DBO.schema_version
                   WHERE version_number = '' '' OR version_number IS NULL' 
                   
EXEC sp_executesql @command

visakh16
Very Important crosS Applying yaK Herder

India
52249 Posts

Posted - 12/03/2012 :  09:47:03  Show Profile  Reply with Quote
if you want to check table being empty, you should be using logic like

IF (
SELECT COUNT(*)
FROM DB.CQ_DBO.schema_version
) = 0
...


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

Go to Top of Page

NeilG
Aged Yak Warrior

United Kingdom
530 Posts

Posted - 12/03/2012 :  09:49:39  Show Profile  Reply with Quote
Try looking at the below:

http://msdn.microsoft.com/en-us/library/aa259229(v=SQL.80).aspx
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.16 seconds. Powered By: Snitz Forums 2000