question

Orasql avatar image
Orasql asked

Update and append a column

I have a table to update a column from another column in the same table and also adding a partial value from another table. For example there are three columns in the same table A, B, C. A = 2020 (This is the first column whose last two digits +1 is required) B= 1(This is the second column its value can be from 1 to 12 so if it is 1 to 9 I have to put a prefix 0 so it will be like 01) C= 0121(This is required)
sql server 2012
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.

GPO avatar image GPO commented ·
Can you describe the underling problem you're trying to solve? Can you post the table definitions and the SQL you've tried to date?
0 Likes 0 ·
tzvikl avatar image
tzvikl answered
Here you go select 2020 as A , 1 AS B, cast(null as varchar(10)) as C into #t1 --select * from #t1 update #t1 set C = Right('0'+cast(B as varchar(2)),2) +cast(Right(A,2)+1 as varchar(2)) select * from #t1
10 |1200

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

Orasql avatar image
Orasql answered
Thanks..That worked :)
10 |1200

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

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.