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
 General SQL Server Forums
 New to SQL Server Programming
 ISNULL function

Author  Topic 

see199
Starting Member

21 Posts

Posted - 2007-06-18 : 21:48:06
SELECT JS_ID = ISNULL(ID.JS_ID,'-')
FROM
dbo.FM_INVOICE I,
dbo.FM_INVOICE_DETAILS ID
WHERE
I.INVOICE_ID = ID.INVOICE_ID
AND WO_ID = '-'--ISNULL(@GetLatest, '-')

is there any mistake i made? because it still return NULL when no data is found. how do i make it return '-' if a null is found

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2007-06-18 : 23:11:51
ISNULL() check the value, if it is NULL, return what you specified instead of the null value.

if no record is found, it is not return NULL but rather no rows are return, @@rowcount is 0.


KH

Go to Top of Page

cvraghu
Posting Yak Master

187 Posts

Posted - 2007-06-19 : 17:17:49
You can declare a variable and initialize to '-'. Use the variable in the subsequent select. This ensures that even if the select did not fetch any rows, the variable has '-'.

Declare @JS_ID varchar(10)

Select @JS_ID = '-'

SELECT @JS_ID = ISNULL(ID.JS_ID,'-')
FROM
dbo.FM_INVOICE I,
dbo.FM_INVOICE_DETAILS ID
WHERE
I.INVOICE_ID = ID.INVOICE_ID
AND WO_ID = '-'--ISNULL(@GetLatest, '-')

Select @JS_ID as JS_ID
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2007-06-20 : 05:09:47
<<
is there any mistake i made? because it still return NULL when no data is found. how do i make it return '-' if a null is found
>>

1 It will return nothing when no records in table
2 It will return - where there are NULLs

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -