Quantcast
Channel: Answers for "How to generate a unique record using server variables ?"
Browsing latest articles
Browse All 6 View Live

Answer by Usman Butt

I guess using DENSE_RANK() function is one way of doing it. For e.g. DECLARE @Data table (col1 varchar(5),col2 varchar(5),col3 varchar(5),col4 varchar(5),Primary Key(col1,col2 )) insert into @Data...

View Article


Answer by Kev Riley

If by server variables you mean some value that is specific to that server,e.g. server name then you can use select cast(@@Servername as varchar(max)) + col1 as col0, * from Data

View Article


Answer by Scot Hauder

As an aside, here is something interesting: SELECT id,d2.* FROM (SELECT NEWID()[id], col1 FROM Data GROUP BY col1)d JOIN Data d2 ON (d2.col1 = d.col1) Why isn't the id for both A rows the same? NEWID...

View Article
Browsing latest articles
Browse All 6 View Live