Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2012 Forums
 SSIS and Import/Export (2012)
 Need to assign numbers

Author  Topic 

shantheguy
Starting Member

22 Posts

Posted - 2013-11-22 : 07:07:00
Hi all,

I have a scenario like following

C1 C2
a 1
b 2
c 3
d 1
e 2
f 3
g 1

i have values for first column need to genarate the second column values as shown.

Please help out. Thanks in advance.

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2013-11-22 : 07:16:07
[code]
SELECT C1,((ROW_NUMBER() OVER (ORDER BY C1)-1)%3)+1 AS C2
FROM Table
[/code]

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page

shantheguy
Starting Member

22 Posts

Posted - 2013-11-26 : 05:49:46
Thanks Visakh... its working
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2013-11-26 : 06:18:06
welcome

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page
   

- Advertisement -