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 |
|
jdelgado
Starting Member
5 Posts |
Posted - 2012-09-20 : 23:07:27
|
| Hi, I been trying to build a query to find out what records are missing a value and so far no luck. What I am trying to get is the RecipeId that don't have a PhaseId =20 in the table tblRecipeSeg. Each recipe can have multiple Segments with and each segment has a PhaseId but I am looking for the recipe that dont have PhaseId 20 like in the sample below recipe Id 39 doesnt have a phaseId of 20.Thanks for your helptables are as follow.tblRecipeRecipeIdRevisionDescriptionComments....tblPhasePhaseIdDescription....tblRecipeSegSegKeyRecipeIdSegIdPhaseIdSample DataSegKey RecipeId SegId PhaseId27 4 1 1728 4 2 1829 4 3 1931 4 4 2032 4 5 2133 4 6 2234 4 7 23326 39 1 17327 39 2 18328 39 3 19330 39 4 21331 39 5 22332 39 6 23333 40 1 17334 40 2 18335 40 3 19336 40 4 20337 40 5 21338 40 6 22339 40 7 23 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2012-09-20 : 23:11:52
|
| [code]SELECT r.*FROM tblrecipe rINNER JOIN (SELECT RecipeId FROM tblRecipeSeg GROUP BY RecipeId HAVING SUM(CASE WHEN PhaseId=20 THEN 1 ELSE 0 END) =0 )sON s.RecipeId = r.RecipeId[/code]------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
jdelgado
Starting Member
5 Posts |
Posted - 2012-09-21 : 07:51:24
|
WOW, Thanks a lotquote: Originally posted by visakh16
SELECT r.*FROM tblrecipe rINNER JOIN (SELECT RecipeId FROM tblRecipeSeg GROUP BY RecipeId HAVING SUM(CASE WHEN PhaseId=20 THEN 1 ELSE 0 END) =0 )sON s.RecipeId = r.RecipeId ------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/
|
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2012-09-21 : 12:24:49
|
| Welcome------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
|
|
|