Monday, February 20, 2012

Rather Simple Logic - Need some advice

I have two tables and I want to validate that the results of a query
match the required structure. In this example, the Bad Query returns
two Row2, it therefore does not match the required structure.
Thanks for the help.
Dave
Actual Results from a Query (Good)
---
PartNo Row Description
6F23-1700034-AP32NC 1 V65-F001G
6F23-1700034-AP32NC 2 V65-S002G
6F23-1700034-AP32NC 3 V65-T032G
Actual Results from a Query (Bad)
---
PartNo Row Description
6F23-1700034-AP32NC 1 V65-F001G
6F23-1700034-AP32NC 2 V65-S002G
6F23-1700034-AP32NC 3 V65-T003G
6F23-1700034-AP32NC 2 V65-S002G
Required Structure
--
Row Description
1 1st Row
2 2nd Row
3 3rd RowA precise definition of 'match required structure' is needed to answer your
question.
IF (SELECT COUNT(*) FROM RequiredStructure) =
(SELECT COUNT(*) FROM ActualResults) AND
(SELECT COUNT(*) FROM RequiredStructure) =
(SELECT COUNT(*)
FROM(
SELECT Row FROM RequiredStructure
UNION
SELECT Row FROM ActualResults
) AS CompareResults
)
PRINT 'Matches'
ELSE
PRINT 'Does not match'
Hope this helps.
Dan Guzman
SQL Server MVP
"Dave" <davel@.here.ca> wrote in message
news:r0em72ln86fhtc5b9gammvvn72d2f7h68f@.
4ax.com...
>I have two tables and I want to validate that the results of a query
> match the required structure. In this example, the Bad Query returns
> two Row2, it therefore does not match the required structure.
> Thanks for the help.
> Dave
>
> Actual Results from a Query (Good)
> ---
> PartNo Row Description
> 6F23-1700034-AP32NC 1 V65-F001G
> 6F23-1700034-AP32NC 2 V65-S002G
> 6F23-1700034-AP32NC 3 V65-T032G
> Actual Results from a Query (Bad)
> ---
> PartNo Row Description
> 6F23-1700034-AP32NC 1 V65-F001G
> 6F23-1700034-AP32NC 2 V65-S002G
> 6F23-1700034-AP32NC 3 V65-T003G
> 6F23-1700034-AP32NC 2 V65-S002G
> Required Structure
> --
> Row Description
> 1 1st Row
> 2 2nd Row
> 3 3rd Row
>

No comments:

Post a Comment