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 |
spunkiegirl
Starting Member
9 Posts |
Posted - 2014-04-13 : 19:21:16
|
Good Afternoon,I have a table named CallNbr with one record per Call. I have another table CallAttributes with labor, travel and parts for each Call.So if I have CallNbr 12345, CallAttributes would look like the below.12345 Labor L 45.0012345 Travel T 30.0012345 Part P 10.00I have another CallNbr 13333, CallAttributes look like the below, it has no parts.13333 Labor L 45.0013333 Travel T 30.00I need a sql script that loops through the CallAttribute table and only returns the CallNbr of records that do not have an entry for Part, so my first example, Call 12345, would not be returned in my result set because it has a Part in the CallAttributes table. My second example, call 13333 would be returned, because there is no Part in the CallAttributes table.Thank you so much! |
|
nagino
Yak Posting Veteran
75 Posts |
Posted - 2014-04-13 : 20:48:00
|
Do you mean following?SELECT [Call]FROM CallNbrWHERE NOT EXISTS( SELECT * FROM CallAttributes T WHERE T.Column2 = 'Part' AND T.Column1 = CallNbr.[Call]) ORSELECT DISTINCT Column1FROM CallAttributesWHERE NOT EXISTS( SELECT * FROM CallAttributes T WHERE T.Column2 = 'Part' AND T.Column1 = CallAttributes.Column1) -------------------------------------From JapanSorry, my English ability is limited. |
|
|
spunkiegirl
Starting Member
9 Posts |
Posted - 2014-04-13 : 21:47:26
|
Thank you so much! The first one worked exactly like I needed! Thank you, Thank you, Thank you!!! |
|
|
|
|
|
|
|