November 24, 2008 at 10:37 am
Hi All
I am comparing 2 counts in a stored procedure. Basically i have this :-
DECLARE @AllMarketsEdbsCount int
DECLARE @UploadedMarketsEdbsCount int
SELECT COUNT(*) AS [@AllMarketsCount]
FROM .......
WHERE ........
SELECT COUNT(*) AS [@UploadedMarketsCount]
FROM .....
WHERE ......
IF @AllMarketsCount = @UploadedMarketsCount
BEGIN
SET @UploadedFinished = 1
END
ELSE
BEGIN
SET @UploadedFinished = 0
END
@AllMarketsCount is 16 and @UploadedMarketsCount is 6.
This is returning 0, which is correct, however, if I change the "=" to for example "<", the result is still the same, ie 0.
Am I doing something wrong?
Thanks for your time
Johann
November 24, 2008 at 10:42 am
SELECT @AllMarketsCount = COUNT(*)
FROM .......
WHERE ........
SELECT @UploadedMarketsCount = COUNT(*)
FROM .....
WHERE ......
____________________________________________________
Deja View - The strange feeling that somewhere, sometime you've optimised this query before
How to get the best help on a forum
http://www.sqlservercentral.com/articles/Best+Practices/61537November 24, 2008 at 10:42 am
You need to change this:
SELECT COUNT(*) AS [@AllMarketsCount]
FROM .......
WHERE ........
SELECT COUNT(*) AS [@UploadedMarketsCount]
FROM .....
WHERE ......
To this:
select @AllMarketsCounty = count(*)
from ...
where ...
select @UpladedMarketsCount = count(*)
from ...
where ...
The version you have in your sample doesn't set the value of the variables, it just selects the data with that as the column name.
Since the variables aren't being assigned values, they are both null, which is never going to return true on any equality/greater/less test.
Try that and see if it does what you need.
- Gus "GSquared", RSVP, OODA, MAP, NMVP, FAQ, SAT, SQL, DNA, RNA, UOI, IOU, AM, PM, AD, BC, BCE, USA, UN, CF, ROFL, LOL, ETC
Property of The Thread
"Nobody knows the age of the human race, but everyone agrees it's old enough to know better." - Anon
November 24, 2008 at 10:51 am
Thanks
SELECT @var = COUNT(*) worked!
Thanks for your help and time!
November 24, 2008 at 11:27 am
@AllMarketsCount is 16 and @UploadedMarketsCount is 6.
IF @AllMarketsCount = @UploadedMarketsCount
This is returning 0, which is correct, however, if I change the "=" to for example "<", the result is still the same, ie 0.
Not to split hairs, but even if you had used the correct syntax, this would still have been a 0, as 16 isn't < 6 :hehe:
November 24, 2008 at 1:18 pm
yes I know
the problem is that all comparisons, wether ' ' were all returning 0
That was the problem
Viewing 6 posts - 1 through 5 (of 5 total)
You must be logged in to reply to this topic. Login to reply