How would I go about the following query?
SELECT
CASE LEN(field1)
WHEN > 15 --Error: Incorrect syntax near '>'.
THEN SUBSTRING(field1, 1, 15)
ELSE field1
END
AS 'My Field'
FROM MyTbl
Can you not do comparisons like this in a CASE clause?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
When you write it the way you had it, think of it like a
switchstatement, where you’re making implicit equality comparisons. If you need more complex logic you need to write theCASEthis way.