Jump to content

[SOLVED] IS NULL (), Something simple.


maliary

Recommended Posts

Hello,

 

I have the query below, for some columns such as Rec. Qty, no values are returned. Where there is no value returned I would like to put the word 'Nothing', instead of having a blank.

 

SELECT T0.[itemCode], T0.[Dscription], T0.[Quantity] as 'Iss. Qty', T0.[DocDate] as 'Iss. Date', T1.[Quantity] as 'Rec. Qty', T0.[u_Newfield], T1.[DocDate] as 'Rev. Date' FROM IGE1 T0

 

LEFT OUTER JOIN IGN1 T1

          ON  T1.[u_GI_Issue] =  T0.[DocEntry] WHERE T0.[u_Newfield] = [%0] and  T0.[DocDate] between [%1] and [%2]

Link to comment
Share on other sites

 

Thanks for pointing me in the right direction IFNULL() does not work with MSSQL, but I used COALESCED instead. But I get the following conversion error

 

ERROR CONVERTING VARCHAR TO NUMERIC  when I use it in on the T1.[Quantity] as 'Rec. Qty' column. Like this

 

COALESCE (T1.[Quantity], 'NOT')

 

Link to comment
Share on other sites

 

Thanks, this works well only that the quantity field is changed to varchar, no problem with that though. However I have tried the same with the DocDate field

but the date format is not the best when not null. I would like to change the date format from Arp 17 2009 - varchar to the datetime format.

 

This I believe would require the use of case or if else statements. but they keep giving me the same error I have been having.

 

 

Link to comment
Share on other sites

I have this

 


SELECT T0.[itemCode], T0.[Dscription], T0.[Quantity] as 'Iss. Qty', T0.[DocDate] as 'Iss. Date', ISNULL (T1.[Quantity],0) ,

CASE
WHEN ISNULL (T1.[Quantity],0) = 0 THEN ISNULL(CAST(T1.[Quantity] AS varchar(50)), 'Nothing') 
WHEN ISNULL (T1.[Quantity],0) != 0 THEN ISNULL(CAST(T1.[Quantity] AS  varchar(50)), 'Nothing') 
END,

CASE
WHEN ISNULL (T1.[DocDate],0) = 0 THEN ISNULL(CAST(T1.[DocDate] AS  Char(20)), 'Nothing') 
WHEN ISNULL (T1.[DocDate],0) != 0 THEN ISNULL(CAST(T1.[DocDate] AS  datetime), 'Nothing') 
END
,
ISNULL(CAST(T1.[Quantity] AS varchar(50)), 'Nothing') as 'Recieved Qty' , T0.[u_Newfield], ISNULL(CAST(T1.[DocDate] AS varchar(50)), 'Nothing')  ,COALESCE (CAST (T1.[DocDate] as Char(20)),'NOT')  as 'Rev. Date' FROM IGE1 T0

LEFT OUTER JOIN IGN1 T1 
         ON  T1.[u_GI_Issue] =  T0.[DocEntry] WHERE T0.[u_Newfield] = [%0] and  T0.[DocDate] between [%1] and [%2]

 

When ISNULL (T1.[DocDate],0) = 0 it throws an error

 

Conversion failed when converting datetime to character string.

Link to comment
Share on other sites

As with previous example you need to output the fields in the same format hence you cannot output 'Nothing' (varchar value) for an integer without CAST(ing) the integer. This is the same for the datetime field as 0  is not a valid datetime value. Your best bet for this is just to output as NULL.

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.