all groups > sql server new users > january 2006 >
You're in the

sql server new users

group:

IF...ELSE problem


IF...ELSE problem Daves
1/26/2006 12:00:00 AM
sql server new users:
if I have a Sql stored proc returning tables based on several IF... ELSE
statements, shouldn't there be only 1 resultset? Because my frontend (Simego
Sql Admin Tools) shows me 4 resultsets as if all 4 SELECT queries where run
although insed IF...ELSE statements

Re: IF...ELSE problem Andrew J. Kelly
1/26/2006 12:00:00 AM
It would be nice to see the actual code so as to know what we are dealing
with. Do you have SET NOCOUNT ON at the beginning of the sp?

--
Andrew J. Kelly SQL MVP


[quoted text, click to view]

Re: IF...ELSE problem Daves
1/26/2006 12:00:00 AM
hi,
NOCOUNT ON doesn't change anything
the code (simplified) is below, it currently returns 7 resultsets!


CREATE PROCEDURE ListNewsItems
(
@GroupID int, @UsersID int
)
AS
IF @UsersID < 1
BEGIN
IF @GroupID = -1 SELECT [...] WHERE [...]
ELSE SELECT NewsID, DateIn, News.Title FROM News WHERE [...]
END

ELSE
BEGIN
DECLARE @IsUserInGroup bit
SET @IsUserInGroup = 0
IF @GroupID = -1 SELECT [...] WHERE [...]
ELSE
BEGIN
SELECT @IsUserInGroup = 1 WHERE [...]

IF @GroupID = 0
BEGIN
IF @IsUserInGroup = 1 SELECT NewsID, DateIn, News.Title FROM
News WHERE [...]
ELSE SELECT NewsID, DateIn, News.Title FROM News WHERE [...]
END
IF @GroupID > 0
BEGIN
IF @IsUserInGroup = 1 SELECT NewsID, DateIn, News.Title FROM
News WHERE [...]
ELSE SELECT NewsID, DateIn, News.Title FROM News WHERE [...]
END
END
END

Re: IF...ELSE problem Andrew J. Kelly
1/26/2006 7:51:55 PM
Yes I agree with Hugo. You can also trace the events at the stmt level to
see what is going on inside the sp.

--
Andrew J. Kelly SQL MVP


[quoted text, click to view]

Re: IF...ELSE problem Hugo Kornelis
1/26/2006 9:58:49 PM
[quoted text, click to view]

Hi Daves,

What happens if you use Query Anaylzer as front-end? If you get just one
resultset there, you know it has to do with Simego. If you get the same
7 resultsets, you'll have to find the errors in your code.

--
Re: IF...ELSE problem Daves
1/27/2006 12:00:00 AM
well that is the problem with Sql Server 2005 Express edition (sorry I know
I said Yukon)... there is no Query Analyzer :(



[quoted text, click to view]

Re: IF...ELSE problem Andrew J. Kelly
1/27/2006 12:00:00 AM
There is sqlcmd. You can also download the Beta for express tools.
http://www.microsoft.com/downloads/details.aspx?familyid=82afbd59-57a4-455e-a2d6-1d4c98d40f6e&displaylang=en

--
Andrew J. Kelly SQL MVP


[quoted text, click to view]

AddThis Social Bookmark Button