maliary Posted April 17, 2009 Share Posted April 17, 2009 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] Link to comment https://forums.phpfreaks.com/topic/154511-error-in-sql-query/ Share on other sites More sharing options...
GeoffOs Posted April 22, 2009 Share Posted April 22, 2009 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') Link to comment https://forums.phpfreaks.com/topic/154511-error-in-sql-query/#findComment-816293 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.