I want to do a select that do a cast only for a specific ID but it doesn’t seems to work.
Example :
SELECT
CASE
WHEN(@ID <> 1) THEN Code
WHEN(@ID = 1) THEN Cast(Code AS int)
END Code FROM ....
Any Idea ?
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.
It works for me. Check if the @id is of type int and if all values of column Code can be casted to int.
UPDATE If you have a value that can’t be casted to int, your query won’t work.
So you can write 2 different queries.
Smth like