Please start any new threads on our new site at We've got lots of great SQL Server experts to answer whatever question you can come up with.

Our new SQL Server Forums are live! Come on over! We've restricted the ability to create new threads on these forums.

SQL Server Forums
Profile | Active Topics | Members | Search | Forum FAQ
Save Password
Forgot your Password?

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

Starting Member

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

Very Important crosS Applying yaK Herder

52326 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 (
FROM DB.CQ_DBO.schema_version
) = 0

SQL Server MVP

Go to Top of Page

Aged Yak Warrior

United Kingdom
530 Posts

Posted - 12/03/2012 :  09:49:39  Show Profile  Reply with Quote
Try looking at the below:
Go to Top of Page
  Previous Topic Topic Next 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.64 seconds. Powered By: Snitz Forums 2000