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 |
|
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 IDWHERE 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 |
 |
|
|
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 IDWHERE I.INVOICE_ID = ID.INVOICE_ID AND WO_ID = '-'--ISNULL(@GetLatest, '-')Select @JS_ID as JS_ID |
 |
|
|
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 table2 It will return - where there are NULLsMadhivananFailing to plan is Planning to fail |
 |
|
|
|
|
|
|
|