Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

How can I delete records base on the value of a fieled in the 1st recor? Expand / Collapse
Author
Message
Posted Monday, December 31, 2012 4:01 PM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Friday, April 26, 2013 8:32 AM
Points: 17, Visits: 68
I generate a small table with a SELECT INTO from a larger table. One of the fields in the new table is 'Org'. I have to treat Org = ABC as a special case. So IF the Org in the first row is ABC, DELETE all other rows.

If the Org in the first row is NOT ABC, keep all rows.

How would I construct this query?
Post #1401520
Posted Monday, December 31, 2012 5:12 PM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: Today @ 8:27 PM
Points: 6,735, Visits: 11,788
Sounds like homework, which is fine, I am happy to help, but please post the some table definitions (CREATE TABLE statements) and some sample data (INSERT statements) as well as your expected results (per the sample data).

__________________________________________________________________________________________________
There are no special teachers of virtue, because virtue is taught by the whole community. --Plato

Believe you can and you're halfway there. --Theodore Roosevelt

Everything Should Be Made as Simple as Possible, But Not Simpler --Albert Einstein

The significant problems we face cannot be solved at the same level of thinking we were at when we created them. --Albert Einstein

1 apple is not exactly 1/8 of 8 apples. Because there are no absolutely identical apples. --Giordy
Post #1401530
Posted Monday, December 31, 2012 7:41 PM


SSC-Insane

SSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-Insane

Group: General Forum Members
Last Login: Today @ 9:51 PM
Points: 21,627, Visits: 27,482
opc.three (12/31/2012)
Sounds like homework, which is fine, I am happy to help, but please post the some table definitions (CREATE TABLE statements) and some sample data (INSERT statements) as well as your expected results (per the sample data).


Plus what you have written so far in an effort to solve your problem.
It helps to know what you have done so that we can guide to the correct solution.



Lynn Pettis

For better assistance in answering your questions, click here
For tips to get better help with Performance Problems, click here
For Running Totals and its variations, click here or when working with partitioned tables
For more about Tally Tables, click here
For more about Cross Tabs and Pivots, click here and here
Managing Transaction Logs

SQL Musings from the Desert Fountain Valley SQL (My Mirror Blog)
Post #1401540
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse