Sybase NNTP forums - End Of Life (EOL)

The NNTP forums from Sybase - forums.sybase.com - are now closed.

All new questions should be directed to the appropriate forum at the SAP Community Network (SCN).

Individual products have links to the respective forums on SCN, or you can go to SCN and search for your product in the search box (upper right corner) to find your specific developer center.

How to get Row Count in SP

2 posts in General Discussion Last posting was on 2003-04-17 02:19:33.0Z
Richard Posted on 2003-04-16 19:49:11.0Z
From: Richard
Date: Wed, 16 Apr 2003 15:49:11 -0400
Newsgroups: ianywhere.public.general
Subject: How to get Row Count in SP
Message-ID: <4B4F7606F1C4076B006CDFC885256D0A.006CDFDB85256D0A@webforums>
Lines: 22
MIME-Version: 1.0
Content-Type: text/plain; charset="us-ascii"
Content-Transfer-Encoding: 7bit
Path: forums-1-dub!forums-master.sybase.com!webforums.sybase.com!news
Xref: forums-1-dub ianywhere.public.general:902
Article PK: 2926

How can the @@RowCount Global variable in a stored proc...I am wanting test
after I make a Selection if I don't have any records then I execute another
Selection.

ALTER procedure DBA.sp_ADM_GetUsers(@UserID char(254))
as
begin
select sf.Feature,svu.Security_Mask from DBA.Sec_Verus_User as svu join
DBA.Sec_Features as sf on sf.Secured_Features_Link_Code =
svu.Secured_Features_Link_Code where
svu.UserName = @UserID
if @@rowcount = 0
select sf.Feature,svu.Security_Mask from DBA.Sec_Verus_User as svu join
DBA.Sec_Features as sf on sf.Secured_Features_Link_Code =
svu.Secured_Features_Link_Code where
svu.UserName = 'Default'
end



Thanks
Richard


Nick Elson Posted on 2003-04-17 02:19:33.0Z
From: "Nick Elson" <no_spam_nicelson@sybase.com>
References: <4B4F7606F1C4076B006CDFC885256D0A.006CDFDB85256D0A@webforums>
Subject: Re: How to get Row Count in SP
Date: Wed, 16 Apr 2003 22:19:33 -0400
Lines: 50
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1106
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1106
Message-ID: <eZKpsgIBDHA.303@forums-1-dub>
Newsgroups: ianywhere.public.general
NNTP-Posting-Host: CPE0050bf17594c-CM014370028576.cpe.net.cable.rogers.com 24.42.73.43
Path: forums-1-dub!forums-master.sybase.com!forums-1-dub.sybase.com
Xref: forums-1-dub ianywhere.public.general:903
Article PK: 3300

@@Rowcount counts rows affected for INSERTs, UPDATEs and DELETEs.
For cursor fetch operations it will reflect the rows fetched. And only
that.

None of which will give you what you are looking for (since the caller will
be
the one fetching the result set).

You will need to issue a different query to do what you want. One
possibility may
be to take advantage of something like a combined query

<<1st query>> and EXISTS ( <<1st query>> ) union [all]
<<2nd query>> and NOT EXISTS ( <<1st query>> )

instead your IF statement.

This would likely run a lot faster than to materialize a "select count into
<<local_var>> "
variation of the first query to check for the same condition.

<Richard> wrote in message
news:4B4F7606F1C4076B006CDFC885256D0A.006CDFDB85256D0A@webforums...
> How can the @@RowCount Global variable in a stored proc...I am wanting
test
> after I make a Selection if I don't have any records then I execute
another
> Selection.
>
> ALTER procedure DBA.sp_ADM_GetUsers(@UserID char(254))
> as
> begin
> select sf.Feature,svu.Security_Mask from DBA.Sec_Verus_User as svu join
> DBA.Sec_Features as sf on sf.Secured_Features_Link_Code =
> svu.Secured_Features_Link_Code where
> svu.UserName = @UserID
> if @@rowcount = 0
> select sf.Feature,svu.Security_Mask from DBA.Sec_Verus_User as svu
join
> DBA.Sec_Features as sf on sf.Secured_Features_Link_Code =
> svu.Secured_Features_Link_Code where
> svu.UserName = 'Default'
> end
>
>
>
> Thanks
> Richard