Solved

how to get stored procedure with "exists" to return a recordset my code can use

Posted on 2008-10-03
3
201 Views
Last Modified: 2010-04-21
Now that I've got "exists" working, when I put it into my stored procedure, I'm not sure how to work with it from my code. My code is:
Set rst = cnn.Execute("AppealExistsSP '" & ParcelNo & "', " & TaxYear)

It seems that whether or not a row exists, the recordset "rst" is always closed. So how can I tell if the 'true' from the stored procedure was printed or not, so my code can decide what to do?
ALTER PROCEDURE [dbo].[AppealExistsSP] 
	@strParNo as varchar(35),
	@intTaxYr as smallint
AS
if exists (select * from Appeals where ParcelNo=@strParNo and TaxYear=@intTaxYr)
begin
print 'true'
end

Open in new window

0
Comment
Question by:GordonPrince
  • 2
3 Comments
 
LVL 32

Expert Comment

by:bhess1
ID: 22635040
Don't print 'true', SELECT it:


ALTER PROCEDURE [dbo].[AppealExistsSP] 
        @strParNo as varchar(35),
        @intTaxYr as smallint
AS
if exists (select * from Appeals where ParcelNo=@strParNo and TaxYear=@intTaxYr)
begin
    SELECT 'true' as Result
END
ELSE
    SELECT 'false' as Result
end

Open in new window

0
 
LVL 32

Accepted Solution

by:
bhess1 earned 125 total points
ID: 22635054
Alternate syntax, using a single SQL Statement:
ALTER PROCEDURE [dbo].[AppealExistsSP] 
        @strParNo as varchar(35),
        @intTaxYr as smallint
AS
SELECT CASE
   WHEN exists (select * from Appeals where ParcelNo=@strParNo and TaxYear=@intTaxYr)
      THEN 'true'
   ELSE 'false'
END as Result

Open in new window

0
 
LVL 4

Author Closing Comment

by:GordonPrince
ID: 31502802
This is very helpful. Thanks for your prompt responses.
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you have heard of RFC822 date formats, they can be quite a challenge in SQL Server. RFC822 is an Internet standard format for email message headers, including all dates within those headers. The RFC822 protocols are available in detail at:   ht…
Occasionally there is a need to clean table columns, especially if you have inherited legacy data. There are obviously many ways to accomplish that, including elaborate UPDATE queries with anywhere from one to numerous REPLACE functions (even within…
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

813 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now