0

I am very new to SQL Server. I want to combine 01-JUL- and a variable with a year to get a date and am doing this:

select 
   *, 
   '01-Jan-1900' as from_date_x, 
   '01-JUL-' + from_finyr as to_date_x
into 
   bbt_item_6_a
from 
   bbt_item_5_finyrs

and am getting the following error:

Conversion failed when converting the varchar value '01-JUL-' to data type int.

I have tried searching for the answer but cannot get it.

Thanks

2 Answers 2

1

It sounds like the from_finyr field has int data type. Instead, you need:

    select *, 
        '01-Jan-1900' as from_date_x, 
        '01-JUL-' + CAST(from_finyr AS varchar(4)) as to_date_x 
    into bbt_item_6_a 
    from bbt_item_5_finyrs
Sign up to request clarification or add additional context in comments.

Comments

0

Following SQL is an example, on how you can combine "01-JUL-" and a variable with a year to get a date: SELECT CAST('01-JUL-' + @varaible AS DATE) AS to_date_x

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.