question

Amir-1400 avatar image
0 Votes"
Amir-1400 asked ZoeHui-MSFT answered

Add two digit to first of another digits

I have some tables in SQL and I want to add two digit (the two digit is a fixed number that is 13 ) to the first of all numbers in a some columns. I used this script but unfortunately it doesn't work accurately:

for example I want to change 991105 to 13991105.

my script is as follow:

use SKraseh;
UPDATE tblOrder SET tblOrder.DateReceived = 13 & [DateReceived]
WHERE (((tblOrder.DateReceived)<>0));




sql-server-generalsql-server-transact-sql
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Viorel-1 avatar image
0 Votes"
Viorel-1 answered Amir-1400 commented

If DateReceived column in int, then:

 update tblOrder 
 set DateReceived = '13' + cast(DateReceived as varchar(max)) -- or: concat('13', DateReceived)
 where DateReceived <> 0

· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Thanks a lot. It worked.

0 Votes 0 ·
ZoeHui-MSFT avatar image
0 Votes"
ZoeHui-MSFT answered

Hi @Amir-1643,

Welcome to Microsoft Q&A.

Glad to hear that the issue has been resolved.

If you have any other question, don't hesitate to post in the forum.

Wish you a nice day!

Regards,

Zoe

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.