Inserting numerous incremental values in a column
Got a table with 1200 rows. Added a new col开发者_如何转开发umn which will contain incremental values - Candidate1 Candidate2 Candidate3 . . . Candidate1200
What is the best way to insert these values , non manual way. I am using SQL Server 2008
Assuming there's an IDENTITY column (I called it id
for this example):
UPDATE YOUR_TABLE
SET new_column = (SELECT 'Candidate'+ CAST(ROW_NUMBER() OVER(ORDER BY yt.id) AS VARCHAR(4))
FROM YOUR_TABLE yt
WHERE yt.id = YOUR_TABLE.id)
You might be able to use ROW_NUMBER
http://msdn.microsoft.com/en-us/library/ms186734.aspx
Perhaps perform a query that gets the row number and use that query to perform an update on the source table where you concatenate the Row Number with 'Candidate'.
精彩评论