Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Why the conditions not meet but the SP still execute?

Posted on 2009-04-08
1
Medium Priority
?
203 Views
Last Modified: 2012-05-06
Hi

I need to compare 2 tables' 2 values, if they are equal, then change the status of 2 tables.

However, even they are not equal, the update command still run.

How can I fix it?

I use MSSQL
ALTER PROCEDURE [dbo].[SP_Complete_Transaction] 
@id int
AS
BEGIN 
BEGIN TRAN Complete_Transaction
	SET NOCOUNT ON;
If (
(select sum(amount) as amount from subtransaction where transactionsid=@id and status=2) = 
(select amount from transactions where id=@id and status=2) 
and 
(select sum(payoutamount) as payoutamount from subtransaction where transactionsid=@id and status=2) =
(select countervalue from transactions where id=@id and status=2)
)
 
update transactions set status = 3 where id =@id
update subtransaction set status = 3 where transactionsid =@id
 
ELSE
 
select id from transactions where id=@id
 
IF @@ERROR <> 0
	ROLLBACK TRAN Complete_Transaction
ELSE
	COMMIT TRAN Complete_Transaction
END

Open in new window

0
Comment
Question by:techques
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 11

Accepted Solution

by:
aaronakin earned 150 total points
ID: 24099371
You need to wrap it in a BEGIN and END if you have more than one line in the IF and ELSE clauses.

IF ...
BEGIN
update transactions set status = 3 where id =@id
update subtransaction set status = 3 where transactionsid =@id
END
ELSE
BEGIN
...
END
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

When writing XML code a very difficult part is when we like to remove all the elements or attributes from the XML that have no data. I would like to share a set of recursive MSSQL stored procedures that I have made to remove those elements from …
Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …

704 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