Jump to content

Error in SQL query


maliary

Recommended Posts

Hello,

 

I have the following query in MSSQL 2005, where T1.[DocDate] is null then it should display NOT RECIEVED, if it is there it should display the date.

 

However I get the error message converting failed when converting datetime from character string

 

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

   CASE 
    WHEN ISDATE (T1.[DocDate]) = 1 THEN T1.[DocDate]
    WHEN ISDATE (T1.[DocDate]) <> 1 THEN COALESCE (CAST (T1.[DocDate] as datetime),'NOT') 
   END 
AS 'Recieved Date'
,
T0.[u_Newfield], T1.[DocDate] as 'Rec. 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]

 

 

I think your error is in this bit

WHEN ISDATE (T1.[DocDate]) <> 1 THEN COALESCE (CAST (T1.[DocDate] as datetime),'NOT') 

 

You have already determined that T1.[DocDate] is null (or at least not a date) so you need to do this:

WHEN ISDATE (T1.[DocDate]) <> 1 THEN COALESCE (T1.[DocDate],'NOT') 

Or Even

WHEN ISDATE (T1.[DocDate]) <> 1 THEN 'NOT') 

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.