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.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 sp returning weird results

Author  Topic 

Mannga
Yak Posting Veteran

70 Posts

Posted - 2001-11-15 : 10:49:51
Hi All,

I have a sp which is returning different results when it is not meant to which I don't understand.

Here is the sp
=====================
select NOIDS.la, dtaLocalAuthorityLookup.District,
SUM(CASE Year WHEN @Year-10 THEN 1 ELSE 0 END) AS "ThisYear-10",
SUM(CASE Year WHEN @Year-9 THEN 1 ELSE 0 END) AS "ThisYear-9",
SUM(CASE Year WHEN @Year-8 THEN 1 ELSE 0 END) AS "ThisYear-8",
SUM(CASE Year WHEN @Year-7 THEN 1 ELSE 0 END) AS "ThisYear-7",
SUM(CASE Year WHEN @Year-6 THEN 1 ELSE 0 END) AS "ThisYear-6",
SUM(CASE Year WHEN @Year-5 THEN 1 ELSE 0 END) AS "ThisYear-5",
SUM(CASE Year WHEN @Year-4 THEN 1 ELSE 0 END) AS "ThisYear-4",
SUM(CASE Year WHEN @Year-3 THEN 1 ELSE 0 END) AS "ThisYear-3",
SUM(CASE Year WHEN @Year -2 THEN 1 ELSE 0 END) AS "ThisYear-2",
SUM(CASE Year WHEN @Year -1 THEN 1 ELSE 0 END) AS "ThisYear-1",
SUM(CASE Year WHEN @Year THEN 1 ELSE 0 END) AS ThisYear

from noids INNER JOIN dtaLocalAuthorityLookup ON NOIDS.LA = dtaLocalAuthorityLookup.LA

where (noids.disease=@DiseCode) and (noids.week <= (@MaxDate - (@Year*100)))

group by noids.la, dtaLocalAuthorityLookup.District

order by dtaLocalAuthorityLookup.District
===================

If I run it with @DiseCode = 52 it returns only one line since there is only one result that matches but if I run it with @DiseCode = 8 it returns 16 rows even thoug there are only 5 matches.

I just returns 0's where as in the previous query it doesn't return anything?

I don't understand why it is different?

   

- Advertisement -