question

mbatchelor55 avatar image
mbatchelor55 asked

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

Here is my sql statement:

(CASE WHEN stud_term_sum_div.trm_cde = '10' THEN ('FALL'+' '+ stud_term_sum_div.yr_cde)

WHEN stud_term_sum_div.trm_cde ='20'

THEN (('SPRING'+' ') + (CAST(stud_term_sum_div.yr_cde AS int)+1))

ELSE ' ' END) AS 'entry_academic_period'

I am trying to add 1 to the yr_cde field which is char(4).
sql-server-2012
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

1 Answer

·
Kev Riley avatar image
Kev Riley answered

After you have added 1 to yr_cde, you will need to re-CAST the value to a character datatype, e.g.

THEN (('SPRING'+' ') + CAST((CAST(stud_term_sum_div.yr_cde AS int)+1)) as varchar)
1 comment
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

mbatchelor55 avatar image mbatchelor55 commented ·

Thank you Kev that worked.

0 Likes 0 ·

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.