Generate and insert no sequence | SQL Server Performance Forums

SQL Server Performance Forum – Threads Archive

Generate and insert no sequence

Hello I have a Table
with CODE_FIELD, NAMEFIELD1,………….,NAMEFIELD50 i want to add one field called NO_SEQUENCE and i have added that field
in Design View in MSSQL. Now what i have to do is Create a NO_SEQUENCE starting From N to No of Records Eg say 5 ,6,7….to no of records it has.
CODE_FIELD, NO_SEQUENCE, NAMEFIELD1
1231234, 6, lasdjlajsd
3324234, 7, q2341234123
3423423, 8, alasdkfasda something like this,
How to write a script to generate that No_Sequence and update that field with that? Thanks for the quick reply
Cant you make use of identity column? Madhivanan Failing to plan is Planning to fail
Thanks for the reply Madhivanan.
the date is already there in other columns
just need to update that one column with the no sequence.
How to do using identity column?
First drop the new created column, than create it again as identity column. I haven’t actually tried this solution but I think it should work.
Thanks mmarovic for the reply
I have tried but didnt worked..
how do you create that sequence in a view?
Assume i have a view and need to have a count for each row in the view
how to do that?

Uhm, is it really view or table?
You’ll have to use SQL 2005 to have the function available which gives you a row number in a query or a view – ROW_ID()? I’m not sure about the official name. In SQL 2000 or earlier, you can only create a stored procedure that will insert the results of your query into a temp table with an identity column, and then returns the data from the temp table. Alternatively, look at your resultset, and check if you can find one or more columns that make up a unique identifier. You can probably work with that data as well – deends on what you want to do with the ordinal value.
]]>