Add two digit to first of another digits

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

SQL Server
SQL Server
A family of Microsoft relational database management and analysis systems for e-commerce, line-of-business, and data warehousing solutions.
12,629 questions
Transact-SQL
Transact-SQL
A Microsoft extension to the ANSI SQL language that includes procedural programming, local variables, and various support functions.
4,547 questions
0 comments No comments
{count} votes

Accepted answer
  1. Viorel 111.7K 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 32,426 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