Welcome to dbFreaks.com!
FAQFAQ    SearchSearch      ProfileProfile    Private MessagesPrivate Messages   Log inLog in

Delete Query SQL?

 
   Database Help (Home) -> MSDE RSS
Next:  send mail in FMP with Exchange Server ?  
Author Message
Kahuna

External


Since: Nov 26, 2003
Posts: 15



(Msg. 1) Posted: Fri Oct 10, 2008 10:25 am
Post subject: Delete Query SQL?
Archived from groups: microsoft>public>sqlserver>msde (more info?)

Hi Folks

Changing some legacy data around to make it compatible to a new system and
need to delete a bunch of duplicate records.

Got the select working here:

SELECT fc_main1, COUNT(fc_main1) AS No_Recs, cd_complex, cd_plant,
ad_analysis_code, MIN(cd_id) AS MinRecNo
FROM component_detail_copy
GROUP BY fc_main1, cd_complex, cd_plant, ad_analysis_code
HAVING (ad_analysis_code >= '21') AND (COUNT(fc_main1) > 1) OR
(ad_analysis_code = '01') AND (COUNT(fc_main1) > 1)

Shows a count of the number of records in the duplicate stack and filters
somewhat.

I thought I had nothing better to do than simply add 'WHERE cd_id NOT IN' to
my select string and a few brackets to get this working is SQLServer
Express, but it's complaining about 'Only one expression without EXISTS' or
some such.

What would I need to do to this string to have it run?

DELETE FROM component_detail_copy
WHERE cd_id NOT IN
(SELECT fc_main1, COUNT(fc_main1) AS No_Recs, cd_complex, cd_plant,
ad_analysis_code, MIN(cd_id) AS MinRecNo
FROM component_detail_copy
GROUP BY fc_main1, cd_complex, cd_plant, ad_analysis_code
HAVING (ad_analysis_code >= '21') AND (COUNT(fc_main1) > 1) OR
(ad_analysis_code = '01') AND (COUNT(fc_main1) > 1))

Appreciate any feedback.

TIA

--
Kahuna
------------

 >> Stay informed about: Delete Query SQL? 
Back to top
Login to vote
Andrea Montanari

External


Since: Sep 13, 2003
Posts: 498



(Msg. 2) Posted: Fri Oct 10, 2008 12:25 pm
Post subject: Re: Delete Query SQL? [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

hi,
Kahuna wrote:
> Hi Folks
>
> Changing some legacy data around to make it compatible to a new
> system and need to delete a bunch of duplicate records.
>
> Got the select working here:
>
> SELECT fc_main1, COUNT(fc_main1) AS No_Recs, cd_complex, cd_plant,
> ad_analysis_code, MIN(cd_id) AS MinRecNo
> FROM component_detail_copy
> GROUP BY fc_main1, cd_complex, cd_plant, ad_analysis_code
> HAVING (ad_analysis_code >= '21') AND (COUNT(fc_main1) > 1) OR
> (ad_analysis_code = '01') AND (COUNT(fc_main1) >
> 1)
> Shows a count of the number of records in the duplicate stack and
> filters somewhat.
>
> I thought I had nothing better to do than simply add 'WHERE cd_id NOT
> IN' to my select string and a few brackets to get this working is
> SQLServer Express, but it's complaining about 'Only one expression
> without EXISTS' or some such.
>
> What would I need to do to this string to have it run?
>
> DELETE FROM component_detail_copy
> WHERE cd_id NOT IN
> (SELECT fc_main1, COUNT(fc_main1) AS No_Recs, cd_complex,
> cd_plant, ad_analysis_code, MIN(cd_id) AS MinRecNo
> FROM component_detail_copy
> GROUP BY fc_main1, cd_complex, cd_plant, ad_analysis_code
> HAVING (ad_analysis_code >= '21') AND (COUNT(fc_main1) > 1) OR
> (ad_analysis_code = '01') AND (COUNT(fc_main1) >
> 1))

usually you have to provide the required DDL and some INSERT INTO in order
to set up a repro scenario so that other people do not have to guess all
that..
anyway, try returning only the relative "id"s to be considered in the NOT IN
clause.. so, instead of
WHERE cd_id NOT IN
(SELECT fc_main1, COUNT(fc_main1) AS No_Recs, cd_complex,
cd_plant, ad_analysis_code, MIN(cd_id) AS MinRecNo.

try returning the ids only, similar to
WHERE cd_id NOT IN
(SELECT [ids to be compared with cd_id] FROM....)

--
Andrea Montanari (Microsoft MVP - SQL Server)
http://www.asql.biz http://www.hotelsole.com
DbaMgr2k ver 0.21.1 - DbaMgr ver 0.65.1 and further SQL Tools
--------- remove DMO to reply

 >> Stay informed about: Delete Query SQL? 
Back to top
Login to vote
Display posts from previous:   
Related Topics:
update query with join? - Given two tables Products and Inventory, I'm trying to set the Inventory QtyInStock = 0 where Products VendorID = 11 and Inventory.ProductID = Products.uid My query generates the follwoing error: "ADO error: Only one expression can be specified in...

Install MSDE in XP - Hi all, I have a problem with MSDE installation. Here is the last part of error log. === Logging stopped: 10/10/2003 17:49:00 === MSI (c) (44:64): Note: 1: 1708 MSI (c) (44:64): Product: Microsoft SQL Server Desktop Engine -- Installation operation...

Clone SQL DB (using VB?) - Hi all, I'm having a SQL Server database called X. For testing and training, I would like to make a copy of the entire DB to Y. This copy should include all data, properties, indexes, views, etc. Unfortunately, all my attempts to automate this..

Pubs and Northwind - I have MSDE 2000 installed but don't know how to connect to pubs or northwind. Could anyone help? Running Svr 03

Password in SQL - Hi, Is there a way I can store password in SQL table as encrypted using SQL table defintion instead of writing code to do encrypt and decrypt? Thanks.
   Database Help (Home) -> MSDE All times are: Pacific Time (US & Canada)
Page 1 of 1

 
You can post new topics in this forum
You can reply to topics in this forum
You can edit your posts in this forum
You can delete your posts in this forum
You can vote in polls in this forum



[ Contact us | Terms of Service/Privacy Policy ]