Add a group id to address book kind of data with SQL

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.

declare @i int






@i= CASE WHEN myColumn is null THEN @i+1 ELSE @i END,


= @i


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s