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 |
|
debshutts
Starting Member
1 Post |
Posted - 2010-09-23 : 13:21:09
|
| Hi all,I am needing to import data from a csv file into a SQL 2000 table. The file has 92 rows of duplicate data, which I would like to delete prior to importing. I have imported the csv file into a temporary table, where I want to delete the duplicate rows, then copy the data into its destination table. When I run the query below I receive the following error: Only one expression can be specified in the select list when the subquery is not introduced with EXISTS.Here's my query: Delete FROM dbo.PlanDefImportWHERE dbo.PlanDefImport.PLAN_ID in (select dbo.PlanDefImport. PLAN_ID, Col001, Col002 from dbo.PlanDefImport, tai.TAIPlan where tai.TAIPlan.Plan_Co = dbo.PlanDefImport.Col001 and tai.TAIPlan.Plan_Plan = dbo.PlanDefImport.Col002)I need to include both columns in my subquery in order to isolate the duplicates, so I can't just get rid of one of these columns. I know there are a number of ways to resolve this, but my brain is tired of staring at it, and I'm hoping someone can help me find the simplest way to get this data dropped. For only 92 rows I could have done this manually about 100 times by now, but it's the principle of the thing, and I really need to learn this. Any help is appreciated. Thanks! Deb |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2010-09-23 : 13:24:33
|
| [code]DELETE tFROM YourTable tINNER JOIN (SELECT Col001, Col002,MIN(Plan_ID) AS MinID FROM YourTable GROUP BY Col001, Col002 )t1ON t1.Col001 = t.Col001AND t1.Col002 = t.Col002AND t1.MinID = t.Plan_ID[/code]------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
|
|
|
|
|
|
|