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 |
|
Zentosoft
Starting Member
1 Post |
Posted - 2004-05-15 : 22:59:20
|
| I have 2 tables. 1 called Sub, the other called Issues.Sub has the following structure.PUB|CUSTNO|STRT_DTE|LAST_ISU|Issues has the following structure.PUB|ISS_ID|VOL_ISU|Because table Sub has some invalid entries, i.e. Sub has some records that has STRT_DTE and some LAST_ISU dates that are not found in the Issues table, I want to filter all these out with a SQL query. I have yet to work it out though.Note that the Issues table contains records such as...ACP|20040101|VOL1ACP|20040201|VOL2ACP|20040301|VOL3BBY|20040115|VOL1BBY|20040220|VOL2So I'm trying to match the STRT_DTE and LAST_DTE from the SUB table with the ISS_ID, and if the dates don't exist in the ISSUES table, then I don't select that record. Please help me. I've been stuck on this for 2 hours now.Thanks.John. |
|
|
derrickleggett
Pointy Haired Yak DBA
4184 Posts |
Posted - 2004-05-16 : 00:01:31
|
| If you do an inner join to the Issues table on both dates, you won't pull back any records that don't exist in Issues. Isn't that all you're saying you want?MeanOldDBAderrickleggett@hotmail.comWhen life gives you a lemon, fire the DBA. |
 |
|
|
nr
SQLTeam MVY
12543 Posts |
Posted - 2004-05-16 : 09:41:49
|
| This will give everything from sub with a match in issuesselect s.*from Sub sjoin issues i1on s.PUB = i1.PUBand s.STRT_DTE = i1.ISS_IDjoin issues i2on s.PUB = i2.PUBand s.LAST_ISU = i1.ISS_IDThis will give the sub and issues recs where they exist - nulls for issues recs that don't existselect *from Sub sleft join issues i1on s.PUB = i1.PUBand s.STRT_DTE = i1.ISS_IDleft join issues i2on s.PUB = i2.PUBand s.LAST_ISU = i1.ISS_ID==========================================Cursors are useful if you don't know sql.DTS can be used in a similar way.Beer is not cold and it isn't fizzy. |
 |
|
|
|
|
|