Hello, SQL2008R2
If I create a view with the following code:
the run the view versus running the code I get different answers for ClientRelated/NonClientRelated for SOME RefNum's.
The view returns the correct values while the t-sql does not of the two RefNum's I am looking at one is correct on both the other is not correct for t-sql.
Any suggestions?
djj
The Lord is my shepherd (Psalm 23) - I need someone to lead me!
If I create a view with the following code:
Code:
SELECT
C.Client,
AM.RefNum,
AM.GroupVal,
AM.MiscVal,
COUNT(AM.RefNum) OVER (PARTITION BY AM.GroupVal, C.Client) AS ClientRelated,
cte.CNT - COUNT(AM.RefNum) OVER (PARTITION BY AM.GroupVal, C.Client) AS NonClientRelated,
cte.CNT AS Total
FROM MyTable1 AM
INNER JOIN MyTable2 C ON AM.[CLIENT NAME] = C.ClientName
INNER JOIN (SELECT GroupVal, COUNT(*) AS CNT
FROM MyTable1
GROUP BY GroupVal
HAVING COUNT(*) > 1) cte ON AM.GroupVal = cte.GroupVal
WHERE AM.GroupVal NOT LIKE '00000%'
AND AM.GroupVal NOT LIKE '99999%'
The view returns the correct values while the t-sql does not of the two RefNum's I am looking at one is correct on both the other is not correct for t-sql.
Any suggestions?
djj
The Lord is my shepherd (Psalm 23) - I need someone to lead me!