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.
Author |
Topic |
vamsidhar.tangutoori
Starting Member
19 Posts |
Posted - 2012-11-14 : 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 0The 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
1974 Posts |
Posted - 2012-11-14 : 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
Master Smack Fu Yak Hacker
7174 Posts |
Posted - 2012-11-14 : 16:37:27
|
Maybe this query doesn't return anythingSelect * From dbo.SYSTEM_USER_SESSIONWhere System_User_Id = 11)select @vSession_Id |
|
|
vamsidhar.tangutoori
Starting Member
19 Posts |
Posted - 2012-11-14 : 16:39:01
|
I am running on SQL server 2012quote: 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
19 Posts |
Posted - 2012-11-14 : 16:43:05
|
Hi,Thanks a lot i used your suggestion and changed the query toDeclare @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 problemquote: Originally posted by sodeep Maybe this query doesn't return anythingSelect * From dbo.SYSTEM_USER_SESSIONWhere System_User_Id = 11)select @vSession_Id
|
|
|
chadmat
The Chadinator
1974 Posts |
Posted - 2012-11-14 : 16:43:43
|
quote: Originally posted by sodeep Maybe this query doesn't return anythingSelect * From dbo.SYSTEM_USER_SESSIONWhere System_User_Id = 11)select @vSession_Id
That is it I bet.-Chad |
|
|
|
|
|
|
|