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)
 SELECT where something might be null?

Author  Topic 

Adagio
Starting Member

5 Posts

Posted - 2007-04-04 : 08:05:24
I'm building a stored procedure where it should select something based on what information is sent to the sp, but some of the information might be empty

I have something like this:

ALTER PROCEDURE dbo.FindQrapport
( @DRIVER nvarchar(30) = '%%', @SHPRNO decimal(18, 0) = ??? )
AS

SELECT ReportNumber
FROM ReportHeader
WHERE (DRIVER1 LIKE @DRIVER OR DRIVER2 LIKE @DRIVER) AND SHPRNO = @SHPRNO

RETURN

Sometimes this gets called where only @DRIVER is set to something and other times @SHPRNO is the only one with a value. If it's the latter it wont be a problem as @DRIVER has a default value that selects everything, but how do you set this for a decimal?

harsh_athalye
Master Smack Fu Yak Hacker

5581 Posts

Posted - 2007-04-04 : 08:07:47
quote:
Originally posted by Adagio

I'm building a stored procedure where it should select something based on what information is sent to the sp, but some of the information might be empty

I have something like this:

ALTER PROCEDURE dbo.FindQrapport
( @DRIVER nvarchar(30) = '%%', @SHPRNO decimal(18, 0) = Null )
AS

SELECT ReportNumber
FROM ReportHeader
WHERE (DRIVER1 LIKE @DRIVER OR DRIVER2 LIKE @DRIVER) AND (@SHPRNO IS NULL or SHPRNO = @SHPRNO)

RETURN

Sometimes this gets called where only @DRIVER is set to something and other times @SHPRNO is the only one with a value. If it's the latter it wont be a problem as @DRIVER has a default value that selects everything, but how do you set this for a decimal?



Harsh Athalye
India.
"The IMPOSSIBLE is often UNTRIED"
Go to Top of Page

Adagio
Starting Member

5 Posts

Posted - 2007-04-04 : 08:41:01
Thanks, can't believe it was that simple :)
Go to Top of Page
   

- Advertisement -