Add a group id to address book kind of data with SQLPosted: February 23, 2009
I have been given a Word document with thsousands users’ information. Each user information is separated with a blank line. I saved the file to an Excel and imported to a SQL table. In the table I want group each user data with a group id for further processing. I used a formula to add the group id in Excel:
=IF(B2="",1+D1,D1). I would like to do it in my SQL Server database. Here is what I came up with in SQL Server:
Assisgn an identity column for the table and I will check the data column ( I named it as myColumn) for the blank row to do the update.
SET@i= CASE WHEN myColumn is null THEN @i+1 ELSE @i END,