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
 General SQL Server Forums
 New to SQL Server Programming
 Help with the ISNULL function as it is not working
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

vamsidhar.tangutoori
Starting Member

19 Posts

Posted - 11/14/2012 :  16:26:05  Show Profile  Reply with Quote
Hi,
I am trying to use the isnull value to pass a variable, but it is not working as to replace the null value with a 0
The code is shown below and the result, please help me as to why this is not working.

CODE:
Declare @vSession_Id int

set @vSession_Id = (Select ISNULL(System_User_Id,0)
From dbo.SYSTEM_USER_SESSION
Where System_User_Id = 11)
select @vSession_Id

RESULT:
(No column name)
NULL

chadmat
The Chadinator

USA
1974 Posts

Posted - 11/14/2012 :  16:35:51  Show Profile  Visit chadmat's Homepage  Reply with Quote
What version? I run the following on 2008 R2, and I get 0:

CREATE TABLE #t1 (c1 int identity(1,1) , c2 int null)

insert into #t1 values (null)

Declare @vSession_Id int

set @vSession_Id = (Select ISNULL(c2,0)
From #t1
Where c1 = 1)
select @vSession_Id



Drop table #t1



-Chad
Go to Top of Page

sodeep
Flowing Fount of Yak Knowledge

USA
7174 Posts

Posted - 11/14/2012 :  16:37:27  Show Profile  Reply with Quote
Maybe this query doesn't return anything

Select * From dbo.SYSTEM_USER_SESSION
Where System_User_Id = 11)
select @vSession_Id
Go to Top of Page

vamsidhar.tangutoori
Starting Member

19 Posts

Posted - 11/14/2012 :  16:39:01  Show Profile  Reply with Quote
I am running on SQL server 2012

quote:
Originally posted by chadmat

What version? I run the following on 2008 R2, and I get 0:

CREATE TABLE #t1 (c1 int identity(1,1) , c2 int null)

insert into #t1 values (null)

Declare @vSession_Id int

set @vSession_Id = (Select ISNULL(c2,0)
From #t1
Where c1 = 1)
select @vSession_Id



Drop table #t1



-Chad


Go to Top of Page

vamsidhar.tangutoori
Starting Member

19 Posts

Posted - 11/14/2012 :  16:43:05  Show Profile  Reply with Quote
Hi,
Thanks a lot i used your suggestion and changed the query to
Declare @vSession_Id int

set @vSession_Id = (Select System_User_Id
From dbo.SYSTEM_USER_SESSION
Where System_User_Id = 11)
select ISNULL(@vSession_Id, 0)

It solved the problem

quote:
Originally posted by sodeep

Maybe this query doesn't return anything

Select * From dbo.SYSTEM_USER_SESSION
Where System_User_Id = 11)
select @vSession_Id


Go to Top of Page

chadmat
The Chadinator

USA
1974 Posts

Posted - 11/14/2012 :  16:43:43  Show Profile  Visit chadmat's Homepage  Reply with Quote
quote:
Originally posted by sodeep

Maybe this query doesn't return anything

Select * From dbo.SYSTEM_USER_SESSION
Where System_User_Id = 11)
select @vSession_Id




That is it I bet.

-Chad
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.05 seconds. Powered By: Snitz Forums 2000