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
 SQL Server 2008 Forums
 Transact-SQL (2008)
 check for null values
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

jassie
Constraint Violating Yak Guru

269 Posts

Posted - 10/18/2012 :  01:41:48  Show Profile  Reply with Quote
In a sql server 2008 r2 database, I have a column that can be null. What I am looking for values that equal zero. The column I am looking at is declared as an ineger.

Thus how do I check for the value = 0, but not select recrods where the value in this column can be null.

How would I do this check in a where statement?

bandi
Flowing Fount of Yak Knowledge

India
2170 Posts

Posted - 10/18/2012 :  01:54:56  Show Profile  Reply with Quote


SELECT *
FROM YourTableName
WHERE ColumnName = 0


--
Chandu
Go to Top of Page

Andy Hyslop
Starting Member

United Kingdom
14 Posts

Posted - 10/18/2012 :  04:35:14  Show Profile  Reply with Quote
Or is you just wanted to return any integers excluding NULLS without hard coding the WHERE


DECLARE @TABLE AS TABLE
(NUMBER INT)

INSERT INTO @TABLE
(NUMBER)

SELECT NULL UNION ALL
SELECT NULL UNION ALL
SELECT 0 UNION ALL
SELECT 1 UNION ALL
SELECT 2 

SELECT  *
FROM    @TABLE
WHERE 
ISNUMERIC(NUMBER) = 1



Andy
Go to Top of Page

webfred
Flowing Fount of Yak Knowledge

Germany
8683 Posts

Posted - 10/18/2012 :  05:34:30  Show Profile  Visit webfred's Homepage  Reply with Quote
copy/paste this into a query window, run it and see what happens.

declare @sample table (id int null)
insert @sample
select null union all
select 5 union all
select 10 union all
select 0 union all
select null

select * from @sample
where id=0

select * from @sample
where id is null

select * from @sample
where id is not null



Too old to Rock'n'Roll too young to die.
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.06 seconds. Powered By: Snitz Forums 2000