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.

Esteemed Advisor
Posts: 5,198

Re: How to implement NoDupKey in SQL server

This is a SAS forum.

Post this question in a SQL Server forum instead.

Data never sleeps
Contributor
Posts: 33

Re: How to implement NoDupKey in SQL server

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

 

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

 

Esteemed Advisor
Posts: 5,198

Re: How to implement NoDupKey in SQL server

No, it's not the same.
Data never sleeps
Contributor
Posts: 33

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: 3,837

Re: How to implement NoDupKey in SQL server

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
  • 309 views
  • 1 like
  • 4 in conversation