| Author |
Topic  |
|
|
vamsidhar.tangutoori
Starting Member
13 Posts |
Posted - 11/14/2012 : 16:26:05
|
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
1949 Posts |
Posted - 11/14/2012 : 16:35:51
|
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 |
 |
|
|
sodeep
Flowing Fount of Yak Knowledge
USA
7173 Posts |
Posted - 11/14/2012 : 16:37:27
|
Maybe this query doesn't return anything
Select * From dbo.SYSTEM_USER_SESSION Where System_User_Id = 11) select @vSession_Id
|
 |
|
|
vamsidhar.tangutoori
Starting Member
13 Posts |
Posted - 11/14/2012 : 16:39:01
|
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
|
 |
|
|
vamsidhar.tangutoori
Starting Member
13 Posts |
Posted - 11/14/2012 : 16:43:05
|
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
|
 |
|
|
chadmat
The Chadinator
USA
1949 Posts |
Posted - 11/14/2012 : 16:43:43
|
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 |
 |
|
| |
Topic  |
|