November 16, 2010 at 10:07 am
Can someone tell me why I'm getting this message when there's no '7' in my expression.
Case when datediff (d, getdate (), [Request_UDF,End Date]) <= 01/31/2011 the 'Phase I'
When datediff (d, getdate (), [Request_UDF,End Date]) > 01/31/2011 and datediff (d, getdate (), [Request_UDF,End Date]) <= 03/31/2011 then 'Phase II'
End
November 16, 2010 at 10:10 am
dates have to be encased is single quotes, as they are not a number.
instead of this:
<= 01/31/2011
--change to this for example
<= '01/31/2011'
change it everywhere you had date strings.
Lowell
November 16, 2010 at 10:23 am
First, you are presumably attempting to compare the integer returned by datediff to a date, but since that date is not enclosed in single quotes, you are actually comparing the integer returned by datediff to 1 divided by 31 divided by 2011.
What, exactly, are you attempting to check for?
Matt
November 16, 2010 at 10:24 am
Thanks for your response.
Just tried your fix. Got the following error msg:
"Conversion failed when converting the varchar value '01/31/2011' to data type int."
November 16, 2010 at 10:31 am
I want to pull all the records with an end dates on or before 01/31/11 and between 02/01/11 and 03/31/11.
November 16, 2010 at 10:34 am
Try this:
CASE
WHEN [Request_UDF,End Date] <= '01/31/2011' THEN 'Phase I'
WHEN [Request_UDF,End Date] BETWEEN '02/01/2011' AND '03/31/2011' THEN 'Phase II'
END
Matt
November 16, 2010 at 10:40 am
Much simplier.........ok, thanks I will give a try
November 16, 2010 at 10:43 am
I got it again! Incorrect Syntax near '7'...........what does that mean? There's no 7 in the expression
November 16, 2010 at 10:46 am
It means exactly that. There is an error near the character '7'. In order to help you further, I will need to see the whole query, not just a single CASE block.
Matt
November 16, 2010 at 11:18 am
jhand6603 (11/16/2010)
I got it again! Incorrect Syntax near '7'...........what does that mean? There's no 7 in the expression
Well, it's probably somewhere else in your query or procedure. Can you post the entire bit of code that you're trying to run?
Wayne
Microsoft Certified Master: SQL Server 2008
Author - SQL Server T-SQL Recipes
November 16, 2010 at 12:01 pm
Maybe make sure you have a name for the column like "SomeName =" (with no quotes) prior to the CASE and a comma after END if there is anything else in the query following the CASE.
You could also add "AS SomeName" (no quotes) after the END of the CASE along with a comma if anything follows.
Oh, and don't forget the comma after what ever comes before the CASE statement.
November 16, 2010 at 2:09 pm
Actually the case is the whole expression. I'm not writing a script, its an expression to create a custom field in a report designer application.
Thanks for your help, I'm going to put in a ticket with application designer.
Viewing 12 posts - 1 through 11 (of 11 total)
You must be logged in to reply to this topic. Login to reply