Yes, it does need a cleanup. This is the result of blending two different
systems into one, but I can modify the StartStop table schema and some
scripts to fix this - eventually.
I tried your query based on WHERE EXISTS and also the one from Jacco Based
on the INNER JOIN and I get different results.
Also, the case WHEN 'N' THEN 'NGC'+
RIGHT(Startstop_Dictation_Log.accession_no, 9)
does not return anything. It should convert
N-03-00001 to NGC-03-00001 but it does not work.
I checked and there are matching records in the two tables.
Any Ideas?
Thanks for your reply, Buddy G
[quoted text, click to view] "Joe Celko" <celko@northface.edu> wrote in message
news:Or7p9CtUDHA.1748@TK2MSFTNGP12.phx.gbl...
> >> I want to delete rows in a table based upon when status_final is 'Y'
> in another table. <<
>
> DELETE FROM Startstop_Dictation_Log
> WHERE EXISTS
> (SELECT *
> FROM Accession AS A1
> WHERE A1.status_final = 'Y'
> AND A1.accession_no =
> CASE SUBSTRING(Startstop_Dictation_Log.accession_no, 1, 1)
> WHEN 'S' THEN 'SC'+ Startstop_Dictation_Log.accession_no
> WHEN 'H' THEN 'SC'+ Startstop_Dictation_Log.accession_no
> WHEN 'A' THEN 'SC'+ Startstop_Dictation_Log.accession_no
> WHEN 'N' THEN 'NCG'+ RIGHT(Startstop_Dictation_Log.accession_no,
> 9)
> END);
>
> But this is a really bad situation in the data model. One minute you
> are claim that the accession_no data element is used in both
> startstop_dictation_log and the Accessions table; fine. But then you
> have a different syntax for the same value in those two locations. This
> needs to be cleaned up.
>
> --CELKO--
> ===========================
> Please post DDL, so that people do not have to guess what the keys,
> constraints, Declarative Referential Integrity, datatypes, etc. in your
> schema are.
>
> *** Sent via Developersdex
http://www.developersdex.com ***
> Don't just participate in USENET...get rewarded for it!