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.
Author |
Topic |
zoe2003
Starting Member
17 Posts |
Posted - 2013-01-07 : 05:20:10
|
Hello all,I need help in generating a unique key for 3 columns in a view.For example : I have a view that returns those columns:f1 f2 f3111 222 333111 222 333aaa bbb cccaaa bbb dddaaa bbb ccc111 222 333I want to add another field that will be a unique key for those 3 fields, like that :key f1 f2 f31 111 222 3331 111 222 3332 aaa bbb ccc3 aaa bbb ddd2 aaa bbb ccc1 111 222 333How can I do it ?I appreciate your help.Thanks,Z. |
|
nigelrivett
Master Smack Fu Yak Hacker
3385 Posts |
Posted - 2013-01-07 : 05:34:04
|
select a.seq, b.*from(select distinct f1.f2,f3 seq = row_number() from tbl) ajoin tbl bon a.f1 = b.f1 and a.f2 = b.f2 and a.f3 = b.f3==========================================Cursors are useful if you don't know sql.SSIS can be used in a similar way.Beer is not cold and it isn't fizzy. |
|
|
sivas2k8
Starting Member
1 Post |
Posted - 2013-01-07 : 06:28:39
|
Try this. Sure you'll find the solution here..http://sivanandsql.blogspot.in/2013/01/genenerating-unique-key-for-3-columns.html |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2013-01-07 : 09:42:04
|
[code]select *from(select dense_rank() over (order by f1,f2,f3) AS key,*from table)t[/code]------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
|
|
zoe2003
Starting Member
17 Posts |
Posted - 2013-01-07 : 10:23:33
|
Thank you all ! |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2013-01-07 : 10:33:51
|
welcome------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
|
|
|
|
|