2
select case  when datepart (mm,getdate())>3 then 'abc' else 2 end

Conversion failed when converting the varchar value 'abc' to data type int.

0

3 Answers 3

5

Your values returned from case must be the same type.

select case  when datepart (mm,getdate())>3 then 'abc' else '2' end
Sign up to request clarification or add additional context in comments.

Comments

2

Try this;

select CASE WHEN
       datepart (mm,getdate())>3 then 'abc' else '2'
       END

From CASE (Transact-SQL)

The data types of else_result_expression and any result_expression must be the same or must be an implicit conversion.

Comments

1

Should be like this

select case  when datepart (mm,getdate())>3 then 'abc' else '2' end

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.