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 |
|
ernie99
Starting Member
12 Posts |
Posted - 2008-11-14 : 07:51:26
|
| Hi everyone, I have only a base level knowledge of SQL, can anyone help me achieve the following?I need to create a script that removes all records from the JobTypeByLocationCode table where the Location Name = 'Inner London', 'Outer London', 'Fringe', 'Rest of England & Wales' and the Job Type Name = 'Main Grade', 'Music Instructor', 'Quality Improvement Officer'The JobTypeLocationCode table only contains code foreign keys for the Location & JobType tables so these codes have to be retreived from the Location and JobType based on the 'Name' strings provided in order to be able to delete the right records.The tables are as follows JobTypeByLocationCodeJobTypeByLocationCode intJobTypeCode intLocationCode intLocationLocationCode intName varchar(50)JobTypeJobTypeCode intName varchar(50)Thanks in advance for your help. |
|
|
acollins74
Yak Posting Veteran
82 Posts |
Posted - 2008-11-14 : 07:57:03
|
| This is a pretty straight forward query. If you know what foreign keys are, you should certainly know how to write this query.Is this a homework question. Check out www.w3schools.com/sql/default.asp its a nice site that will teach you sql to a more comfortable level. Then when your stumped, post your problems and people will help you along. |
 |
|
|
ernie99
Starting Member
12 Posts |
Posted - 2008-11-14 : 08:08:59
|
| Solved this is the sqldelete from jobtypebylocation where jobtypebylocationcode in(select jobtypebylocationcodefrom jobtypebylocation jinner join jobtype jt on jt.jobtypecode = j.jobtypecodeinner join location l on l.locationcode = j.locationcodewhere j.jobtypecode in(SELECT JOBTYPECODE FROM JOBTYPEWHERE '%Main Grade, Music Instructor, Quality Improvement Officer%' LIKE '%' + [NAME] + '%')and j.locationcode not in(SELECT locationcodeFROM LOCATION WHERE '%Scotland%' LIKE '%' + [NAME] + '%')) |
 |
|
|
|
|
|