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 2005 Forums
 Transact-SQL (2005)
 Duplicates

Author  Topic 

arkiboys
Master Smack Fu Yak Hacker

1433 Posts

Posted - 2008-05-08 : 06:49:01
Hi,
This is the query which shows me the duplicates
Some of the records have more than one records
I would like to know how to delete the extra records so that I will end up with one record per row.

select
Pricing_Source,
VaR_Identifier,
Price_Date,
PX_Last,
Count(*) as 'count'
from
tblPricesClean
group by
Pricing_Source,
VaR_Identifier,
Price_Date,
PX_Last
having count(*) > 1
order by
count desc

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2008-05-08 : 06:56:08
http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=6256

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

arkiboys
Master Smack Fu Yak Hacker

1433 Posts

Posted - 2008-05-08 : 07:20:01
Hi,
I looked at the link. thanks
This is what i have now but the last part where there is a delete seems to be incorrect.
Can you see anything wrong with my steps please?

the error is:
The multi-part identifier "##t.Pricing_Source" could not be bound.

create table ##t(Pricing_Source nvarchar(10),VaR_Identifier nvarchar(50),Price_Date datetime,PX_Last float,id int not null identity) on [primary]
go

insert into ##t(Pricing_Source,VaR_Identifier,Price_Date,PX_Last)
select
Pricing_Source,
VaR_Identifier,
Price_Date,
PX_Last--,
--Count(*) as 'count'
from
tblPricesClean
group by
Pricing_Source,
VaR_Identifier,
Price_Date,
PX_Last
having count(*) > 1
--order by
--count desc
go
select * from ##t
go
Delete from ##t where id <
(Select Max(id) from ##t t
where ##t.Pricing_Source = t.Pricing_Source and
##t.VaR_Identifier = t.VaR_Identifier and
##t.Price_Date = t.Price_Date and
##t.PX_Last = t.PX_Last)
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-05-08 : 07:39:35
quote:
Originally posted by arkiboys

Hi,
I looked at the link. thanks
This is what i have now but the last part where there is a delete seems to be incorrect.
Can you see anything wrong with my steps please?

the error is:
The multi-part identifier "##t.Pricing_Source" could not be bound.

create table ##t(Pricing_Source nvarchar(10),VaR_Identifier nvarchar(50),Price_Date datetime,PX_Last float,id int not null identity) on [primary]
go

insert into ##t(Pricing_Source,VaR_Identifier,Price_Date,PX_Last)
select
Pricing_Source,
VaR_Identifier,
Price_Date,
PX_Last--,
--Count(*) as 'count'
from
tblPricesClean
group by
Pricing_Source,
VaR_Identifier,
Price_Date,
PX_Last
having count(*) > 1
--order by
--count desc
go
select * from ##t
go
Delete from ##t where id <
(Select Max(id) from ##t t
where t.Pricing_Source = t.Pricing_Source and
t.VaR_Identifier = t.VaR_Identifier and
t.Price_Date = t.Price_Date and
t.PX_Last = t.PX_Last)



Use the alias rather than temp table name. Any special reason why u used global temporary table?
Go to Top of Page

arkiboys
Master Smack Fu Yak Hacker

1433 Posts

Posted - 2008-05-08 : 08:15:19
Solved. thanks
Go to Top of Page
   

- Advertisement -