0

I have a variable,

DECLARE @CN int = (SELECT [CONTROL_NUMBER] FROM myTable)

I need to do an insert statement where the value of this variable is incremented during run time.

So,

INSERT INTO myTable2 (ControlNumber)
SELECT CNC+(@CN increment the value here) FROM aTable

So the values inserted will be like,

aa1234
ab1235
cd1236...

etc.

Definitely @CN is an int, so I will account for changing it to string before inserting the value.

Appreciate the help.

Thanks!

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
OBL
  • 1,347
  • 10
  • 24
  • 45

1 Answers1

1
SET @CN = @CN + 1
INSERT INTO myTable2 (ControlNumber) 
SELECT CNC + Cast(@CN as varchar) FROM aTable 
Warren Rox
  • 655
  • 2
  • 8
  • 23
  • Event though OP should probably being using an Identity column and a separate VARCHAR/CHAR column, this does technically answer his question. +1 @OBL, please rethink your design here. – Tom Halladay May 10 '12 at 03:42