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 |
|
monfu
Yak Posting Veteran
81 Posts |
Posted - 2008-11-24 : 12:38:31
|
| Hi AllI am comparing 2 counts in a stored procedure. Basically i have this :-DECLARE @AllMarketsEdbsCount intDECLARE @UploadedMarketsEdbsCount intSELECT COUNT(*) AS [@AllMarketsCount]FROM .......WHERE ........SELECT COUNT(*) AS [@UploadedMarketsCount]FROM .....WHERE ......IF @AllMarketsCount = @UploadedMarketsCount BEGIN SET @UploadedFinished = 1 ENDELSE 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 timeJohann |
|
|
bjoerns
Posting Yak Master
154 Posts |
Posted - 2008-11-24 : 12:40:35
|
| Since 16 is not lower than 6, I expect 0 actually... |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-11-24 : 12:42:51
|
you cant assign values to variables like this. it should be as below. try like this and seeDECLARE @AllMarketsEdbsCount intDECLARE @UploadedMarketsEdbsCount intSELECT @AllMarketsCount=COUNT(*) FROM .......WHERE ........SELECT @UploadedMarketsCount = COUNT(*) FROM .....WHERE ......IF @AllMarketsCount = @UploadedMarketsCountBEGINSET @UploadedFinished = 1ENDELSEBEGINSET @UploadedFinished = 0END i guess in your case variables where never assigned values so it tokk default value which is NULL so it will always return the else part value 0 as NULL <> NULL under any case. |
 |
|
|
monfu
Yak Posting Veteran
81 Posts |
Posted - 2008-11-24 : 12:51:33
|
| ThanksSELECT @var = COUNT(*) worked!Thanks for your help and time! |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-11-24 : 12:54:53
|
Cheers |
 |
|
|
|
|
|