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
 General SQL Server Forums
 New to SQL Server Programming
 SELECT QUERY

Author  Topic 

godspeedba
Yak Posting Veteran

90 Posts

Posted - 2009-11-02 : 05:51:22
declare @strSQL varchar(5000)
declare @itemtable table (primary_key INT IDENTITY(1,1) NOT NULL,
so_id int,
prop_id int)

INSERT INTO @itemtable (so_id, prop_id)
SELECT so_id, so_bnbid from tb_specialoffer where so_bnbid not in (Select prop_id from @itemtable)


Dear friends
This is hard to explain, so I will give it a try. I am trying to make a selection from tb_specialoffer with ideally a unique so_bnbid.
The table contains a lot of duplicate so_bnbid. Which one of the records it grabs it does not matter.

I tried the above but it copies all of the data into a temptable. Any ideas what I am doing wrong?

bklr
Master Smack Fu Yak Hacker

1693 Posts

Posted - 2009-11-02 : 05:54:43
try like this to avoid duplicate records

select * from
(select row_number()over(partition by so_id,prop_id order by so_id)as rid ,* from tb_specialoffer
)s where rid = 1
Go to Top of Page
   

- Advertisement -