Add two digit to first of another digits

Karim Vazirinejad 186 Reputation points
2021-04-03T06:47:10.737+00:00

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));

Developer technologies | Transact-SQL
SQL Server | Other
0 comments No comments
{count} votes

Accepted answer
  1. Viorel 122.6K Reputation points
    2021-04-03T06:52:19.823+00:00

    If DateReceived column in int, then:

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

1 additional answer

Sort by: Most helpful
  1. ZoeHui-MSFT 41,491 Reputation points
    2021-04-05T06:16:56.587+00:00

    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

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.