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 2005 Forums
 Transact-SQL (2005)
 pass parameter

Author  Topic 

arkiboys
Master Smack Fu Yak Hacker

1433 Posts

Posted - 2009-11-19 : 10:35:20
Hello,
The query below does not return any records.

declare @value tinyint
set @value = null

select
field1
from
table1
where
field2 = 1
and field3 = null

The query below does return value because I am using and field3 is null
declare @value tinyint
set @value = null

select
field1
from
table1
where
field2 = 1
and field3 is null

Question
How can I make the query below to return results by passing a parameter for the value, See query below
Note that this query gives an error because I am using = @value

Thanks

declare @value tinyint
set @value = null

select
field1
from
table1
where
field2 = 1
and field3 = @value

jimf
Master Smack Fu Yak Hacker

2875 Posts

Posted - 2009-11-19 : 11:47:40
Why would using field3 = @value give you an error? Do you want to pass @value in as a null sometimes? If a value is provided, do you not want where field3 is null?

and isnull(field3,0) = isnull(@value,0)

Jim

Everyday I learn something that somebody else already knew
Go to Top of Page

arkiboys
Master Smack Fu Yak Hacker

1433 Posts

Posted - 2009-11-20 : 03:59:04
I see.
Thank you
Go to Top of Page
   

- Advertisement -