Jump to content
  • 0

Calculated field to compare dates or return text


bradmanning
 Share

Question

I'm trying to use a calculated field for an action tracker. I'm looking to have a field say how long it took to complete an action or if it's incomplete. Here's the code I scraped together:

CASE

WHEN (IsDate([@field:Root_Cause_Identification_Date])=1)

THEN Datediff(day,[@field:Trigger_Date],[@field:Root_Cause_Identification_Date])

ELSE 'Not Complete'

END

I keep getting the following error: Conversion failed when converting the varchar value 'Not Complete' to data type int.

Anyone have any recommendations?

Link to comment
Share on other sites

1 answer to this question

Recommended Posts

  • 0
Quote

CASE

WHEN (IsDate([@field:Root_Cause_Identification_Date])=1)

THEN Datediff(day,[@field:Trigger_Date],[@field:Root_Cause_Identification_Date])

ELSE 'Not Complete'

END

You are getting this error, because the result of Datediff is integer, and 'Not complete' is a varchar. However, one calculated field cannot have a different data type. So,  you need to convert first statement result to a varchar:

cast( Datediff(day,[@field:Trigger_Date],[@field:Root_Cause_Identification_Date]) as varchar)

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  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.

Loading...
 Share

×
×
  • Create New...