Jump to content

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]

 

 

Link to comment
https://forums.phpfreaks.com/topic/154511-error-in-sql-query/
Share on other sites

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

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.