|
-
Jan 16th, 2004, 11:21 AM
#1
Thread Starter
Frenzied Member
SQL Delete question
The first SQL code below is in an existing db's queries. What I'm wondering is why [Main].[Hospital] is in there 3 times? Wouldn't once be sufficient? The full table with all hospitals (3 of them) gets imported into a new db, then all data except for 1 get deleted. Wouldn't the second code do the same thing?
VB Code:
DELETE [Main].[Hospital] AS Expr1, [Main].[Hospital] AS Expr2, [Main].[Hospital] AS Expr3
FROM Main
WHERE ((([Main].[Hospital])<>[Which Hospital?]));
VB Code:
DELETE Hospital as Expr1 FROM Main WHERE Hospital <> [Which Hospital?]
-
Jan 16th, 2004, 03:04 PM
#2
Not quite. The line WHERE ((([Main].[Hospital])<>[Which
Hospital?])); will prompt the user to enter the hospital name not
to delete three times because there are three alias', I believe,
and the fourth will be deleted since it was not entered. [Which
Hospital?] is an unknown field so Access (I assume) will prompt
you for the value of that field to use.
To optimize this query test...
Code:
DELETE Hospital FROM Main WHERE Hospital = [Which Hospital to DELETE?]
This is reverse logic. Instead of
asking which tables not to delete, try deleting only one which the
user prompt will provide. Then import the remaining three tables
into the new database.
Try this out on a copy or test database and verify if it produces
the desired effect before using any code modifications on a live
production database.
HTH.
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Jan 16th, 2004, 03:14 PM
#3
First, I've _never_ gotten a delete to work with fields listed.... but then Access is weird....
Code:
DELETE FROM Main WHERE Hospital = [Hospital to delete?]
Should be sufficient.
TG
-
Jan 16th, 2004, 03:18 PM
#4
Oops, I included Hospital in the DELETE list by mistake.
TG is right, should be left empty or Main.
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Jan 16th, 2004, 06:03 PM
#5
Thread Starter
Frenzied Member
Originally posted by RobDog888
Not quite. The line WHERE ((([Main].[Hospital])<>[Which
Hospital?])); will prompt the user to enter the hospital name not
to delete three times because there are three alias', I believe,
and the fourth will be deleted since it was not entered. [Which
Hospital?] is an unknown field so Access (I assume) will prompt
you for the value of that field to use.
Yes, Access currently prompts for the parameter, but only does so once. I want to put this in code instead of using a built in query, using an input box to get the hospital to keep. Something like
VB Code:
strHospital = InputBox("Enter Hospital")
strSQL = "DELETE Hospital FROM Main WHERE Hospital <> '" & strHospital & "'"
Now that I think about it, maybe it shoud be
VB Code:
DELETE * FROM Main WHERE Hospital <> strHospital
since I don't want any of the data from the other two hopitals in the copied db.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|