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.
| 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 duplicatesSome of the records have more than one recordsI 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 tblPricesCleangroup by Pricing_Source, VaR_Identifier, Price_Date, PX_Lasthaving count(*) > 1order 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=6256MadhivananFailing to plan is Planning to fail |
 |
|
|
arkiboys
Master Smack Fu Yak Hacker
1433 Posts |
Posted - 2008-05-08 : 07:20:01
|
| Hi,I looked at the link. thanksThis 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]goinsert into ##t(Pricing_Source,VaR_Identifier,Price_Date,PX_Last)select Pricing_Source, VaR_Identifier, Price_Date, PX_Last--, --Count(*) as 'count'from tblPricesCleangroup by Pricing_Source, VaR_Identifier, Price_Date, PX_Lasthaving count(*) > 1--order by --count descgoselect * from ##tgoDelete 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) |
 |
|
|
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. thanksThis 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]goinsert into ##t(Pricing_Source,VaR_Identifier,Price_Date,PX_Last)select Pricing_Source, VaR_Identifier, Price_Date, PX_Last--, --Count(*) as 'count'from tblPricesCleangroup by Pricing_Source, VaR_Identifier, Price_Date, PX_Lasthaving count(*) > 1--order by --count descgoselect * from ##tgoDelete from ##t where id < (Select Max(id) from ##t t where t.Pricing_Source = t.Pricing_Source andt.VaR_Identifier = t.VaR_Identifier andt.Price_Date = t.Price_Date andt.PX_Last = t.PX_Last)
Use the alias rather than temp table name. Any special reason why u used global temporary table? |
 |
|
|
arkiboys
Master Smack Fu Yak Hacker
1433 Posts |
Posted - 2008-05-08 : 08:15:19
|
| Solved. thanks |
 |
|
|
|
|
|
|
|