April 21, 2010 at 8:20 pm
Hi All,
I have a stored procedure that requests one parameter which is a bit field. In the stored procedure I want to check if the parameter is null and then perform a different select statement but I can't get my head around how to do this. Any thoughts that might lead me in the right direction?
Cheers
ab
April 21, 2010 at 9:07 pm
andy behrendt (4/21/2010)
Hi All,I have a stored procedure that requests one parameter which is a bit field. In the stored procedure I want to check if the parameter is null and then perform a different select statement but I can't get my head around how to do this. Any thoughts that might lead me in the right direction?
Cheers
ab
CREATE PROC dbo.Test (
@BitField bit = NULL -- so that an entry isn't required
)
AS
SET NOCOUNT ON
IF @BitField IS NULL print '@BitField is null'
ELSE IF @BitField = 'TRUE' print '@BitField is True'
ELSE IF @BitField = 'FALSE' print '@BitField is False'
GO
exec dbo.Test
exec dbo.Test 'True'
exec dbo.Test 'False'
GO
DROP PROC dbo.Test
GO
Wayne
Microsoft Certified Master: SQL Server 2008
Author - SQL Server T-SQL Recipes
April 21, 2010 at 9:32 pm
Cheers for that. I realise now my syntax was at fault as I was trying variations of IsNull and getting the wrong results.
ab
Viewing 3 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply