How to implement NoDupKey in SQL server

Reply
Occasional Contributor
Posts: 7

How to implement NoDupKey in SQL server

Please suggest how to implement SAS- NodupKey in SQL server.

Super User
Posts: 5,876

Re: How to implement NoDupKey in SQL server

Posted in reply to VinayakKankate

This is a SAS forum.

Post this question in a SQL Server forum instead.

Data never sleeps
Contributor
Posts: 35

Re: How to implement NoDupKey in SQL server

Posted in reply to VinayakKankate

I'm not exactly sure what you're trying to do but I would suggest DISTINCT.

 

http://www.w3schools.com/sql/sql_distinct.asp

 

Super User
Posts: 5,876

Re: How to implement NoDupKey in SQL server

Posted in reply to VinayakKankate
No, it's not the same.
Data never sleeps
Contributor
Posts: 35

Re: How to implement NoDupKey in SQL server

That's the reason I pointed out I'm not sure what they are trying to do. Distinct may get them moving in the right direction.

Respected Advisor
Posts: 4,736

Re: How to implement NoDupKey in SQL server

Posted in reply to VinayakKankate

It's not really a question for a SAS Forum but: If you're really after NODUPKEY then you could use the ROW_NUMBER() - if run out of SAS then within a pass-through SQL block.

Have your keys in the partition clause, use any variable in the order by clause, then only select rows where row_number is 1.

 

ROW_NUMBER ( )   
    OVER ( [ PARTITION BY value_expression , ... [ n ] ] order_by_clause ) 

 

Ask a Question
Discussion stats
  • 5 replies
  • 521 views
  • 1 like
  • 4 in conversation