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 2000 Forums
 SQL Server Development (2000)
 Excluding duplicate records (warning newbie)

Author  Topic 

callmejabba
Starting Member

4 Posts

Posted - 2005-07-12 : 15:26:54
I am a newbie. I have to write a query that brings back an product_number (which is unique) and its corresponding action_code. Problem is that a product_number and have multiple action_codes so the results will come back something like this:

Product_nbr action_code
A20191 DEC
A20191 FRO
A20191 PP

Is there a way so I can get out the redundant product_nbr's and have it display something like this:

Product_nbr action_code1 action_code2
A20191 DEC FRO

clarkbaker1964
Constraint Violating Yak Guru

428 Posts

Posted - 2005-07-12 : 16:36:34
if you dont have to many you could use a case statement.

select distinct product_nbr,
case action_code when 'DEC' then action_code as action_code1,
case action_code when 'FRO' then action_code as action_code2,

If You have many action_codes this can become ugly.


You can do anything at www.zombo.com
Go to Top of Page

callmejabba
Starting Member

4 Posts

Posted - 2005-07-13 : 10:01:38
There are a possibility of 80 action codes, so I guess I may be going at this the wrong way :(

No product as more than 3-5 but each product could be any of those 80
Go to Top of Page
   

- Advertisement -