0

I have a table as below:

CtId    CustomerID
1   2600000897685
2   NULL
3   2600000089765
4   NULL
5   2600789657465
6   NULL
7   NULL
8   NULL

I need a sql script updating null column id with my custom unique id. Increment unique number starts from:

2900000000001
2900000000002
.
.
Tun
  • 824
  • 3
  • 16
  • 30

1 Answers1

3

Try this:

declare @i bigint  = 2900000000001

update tablename
set customerId = CONVERT(NVARCHAR(30),@i) , @i = @i + 1    
where customerId is null
Rahul Tripathi
  • 168,305
  • 31
  • 280
  • 331
  • got this error. Arithmetic overflow error converting expression to data type int. – Tun Apr 10 '15 at 10:20
  • Also want to mention that customerId datatype is nvarchar in the table. – Tun Apr 10 '15 at 10:25
  • based on updated info from OP, add a `CONVERT` here `set customerId = CONVERT(NVARCHAR(30),@i) , @i = @i + 1` – ughai Apr 10 '15 at 10:49