473,796 Members | 2,765 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Stored procedure incorrect?

6 New Member
I have written the following Stored Procedure and need input as to what could be wrong with my coding or is there a possibility that not getting the correct results is not in the procedure at all?
Expand|Select|Wrap|Line Numbers
  1. ALTER PROCEDURE spIssueScannedTickets
  2.         @iEventID int,
  3.         @MemberNum nvarchar(12),
  4.         @BatchSize int,
  5.         @FirstNumber nvarchar(12),
  6.         @LastNumber nvarchar(12),
  7.         @SlotsBalance int,
  8.         @TableBalance int,
  9.         @BonusBalance int,
  10.         @UserID int
  11. AS
  12. DECLARE @Result int
  13. SET @Result = 0
  14. BEGIN TRANSACTION
  15. if  (@SlotsBalance>0)
  16. INSERT INTO TicketsIssued (Date, EventID, MemberNumber, EarnType, NumTicketsIssued, Turnover, UserID)
  17.          VALUES (GETDATE(),@iEventID,@MemberNum, 'Slots', @SlotsBalance, 0, @UserID)
  18. SELECT @Result = @@error IF @Result <> 0 BEGIN ROLLBACK TRANSACTION RETURN @Result END
  19.  
  20. if  (@TableBalance>0)
  21. INSERT INTO TicketsIssued (Date, EventID, MemberNumber, EarnType, NumTicketsIssued, Turnover, UserID)
  22.          VALUES (GETDATE(),@iEventID,@MemberNum, 'Tables', @TableBalance, 0, @UserID)
  23. SELECT @Result = @@error IF @Result <> 0 BEGIN ROLLBACK TRANSACTION RETURN @Result END
  24.  
  25. if  (@BonusBalance>0)
  26. INSERT INTO TicketsIssued (Date, EventID, MemberNumber, EarnType, NumTicketsIssued, Turnover, UserID)
  27.          VALUES (GETDATE(),@iEventID,@MemberNum, 'Bonus', @BonusBalance, 0, @UserID)
  28. SELECT @Result = @@error IF @Result <> 0 BEGIN ROLLBACK TRANSACTION RETURN @Result END
  29.  
  30. INSERT INTO BundlesIssued (MemberNumber, EventID, BundleSize, FirstNumber, LastNumber, DateIssued, UserID, Invalid)
  31.         VALUES (@MemberNum, @iEventID, @BatchSize, @FirstNumber, @LastNumber, GETDATE(), @UserID , 0x00)
  32. SELECT @Result = @@error IF @Result <> 0 BEGIN ROLLBACK TRANSACTION RETURN @Result END
  33.  
  34. COMMIT TRANSACTION
  35. SELECT @Result = @@error IF @Result <> 0 RETURN @Result
  36. SET @Result = @BatchSize RETURN @Result
  37. GO
  38.  
As far as I am aware what I have written should give an "all or nothing situation". In other words either all tables are updated or none are.
Comments please.
Jul 31 '08 #1
1 1191
ck9663
2,878 Recognized Expert Specialist
Looks like it's rolling back.

Try executing it as a series of t-sql first. Define the parameters as variables and hard code the values.

Try putting a PRINT 1 or SELECT 1 (then SELECT 2..then 3...then 4) on all rollback. You'll see where it's falling. Like DEBUG mode

-- CK
Jul 31 '08 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

9
5487
by: Ralph Cramden | last post by:
I'm writing a VB6 app which calls several stored procedures on my SQL Server DB. The first stored procedure must complete its inserts before the second stored procedure can query the modified table for its results. My problem is that the second stored procedure occasionally returns a different result set, acting as if the first stored procedure didn't complete (or didn't run).
13
10449
by: dawatson833 | last post by:
I have several stored procedures with parameters that are defined with user defined data types. The time it takes to run the procedures can take 10 - 50 seconds depending on the procedure. If I change the parameter data types to the actual data type such as varchar(10), etc., the stored procedure takes less that a second to return records. The user defined types are mostly varchar, but some others such as int. They are all input type...
4
13470
by: marc | last post by:
I've been developing a stored procedure that uses a user defined function in the query portion of the procedure. However, since the end product needs to allow for dynamic table names, the UDF will not work. I've been trying to get this to work with converting the UDF to a procedure, but I'm having no luck. Here is the background on what I'm trying to accomplish. I need to perform a sub-identity on a table, I have the normal identity set,...
5
2843
by: microsoft.private.windows.netserver.setup | last post by:
I have a very strange thing occurring in the program. I have a dataset retrieved from a stored procedure that just select * from a table. I then try to use the SQlCommandBuilder on the dataset, and fails. I try the same select statement directly and not using a stored procedure and use SQLCommandBuilder, the program works. This is a ASP.net page, and I am stumped. I would like to use the stored procedure rather than controlling it in...
3
1472
by: Jack Black | last post by:
Help!! I'm trying to call a custom stored procedure from a VB.Net code-behind page in an ASP.Net application, and I keep getting an error with no real helpful info... Basically, I'm accepting a username and password from a front-end, and performing a simple INSERT into a SQL Server table via a custom stored procedure in the database. All privileges are fine, and the stored procedure works fine (inserts records perfectly; tested with...
9
4815
by: Problematic coder | last post by:
The intention is to call a stored proceedure which sets flags in the database, this requires no parameters and the page does not need an output from the stored proceedure, though is this is necessary I could change that. Here is the code I am using: Dim objcom2 = New Data.OracleClient.OracleCommand With objcom2 .Connection = objcnn
5
3629
by: Dennis | last post by:
Hi I'm trying to alter my stored procedure to take a parameter for the Database Name, but as usual the syntax is killing me. Thanks for any help Dennis '--------------------------------------------------------------------------­-------------------------------- Before - This Works without a paramater '--------------------------------------------------------------------------­--------------------------------
5
1783
by: bbawa1 | last post by:
I have the following stroed procedue. But whebnnI execute it it gives me following errors. Could you please tell me what is wrong Msg 156, Level 15, State 1, Procedure usp_DateDiff, Line 43 Incorrect syntax near the keyword 'SELECT'. Msg 156, Level 15, State 1, Procedure usp_DateDiff, Line 47 Incorrect syntax near the keyword 'select'. Msg 156, Level 15, State 1, Procedure usp_DateDiff, Line 52 Incorrect syntax near the keyword...
1
1063
by: sweatha | last post by:
Hi I have to convert the following query into stored procedure "select DoctorMaster.FirstName+''+DoctorMaster.MiddleName+''+DoctorMaster.LastName as DoctorsName,DoctorMaster.DRID,DoctorMaster.Gender,DrClinicDetails.Address,DoctorMaster.Telephone+','+DoctorMaster.Mobile as Phone,PrimaryTitle.PrimaryTitle from DoctorMaster,DrClinicDetails,PrimaryTitle,Specialty where DoctorMaster.FirstName like '" + obj.ToString() + "%' or...
2
2821
by: priyamtheone | last post by:
I'm trying to create a stored procedure in MSSQL Server 2005 that'll perform the following jobs: 1) Create a login. 2) Create an user in TestDB database for the login created in step 1. 3) Assign the role 'db_generaluser' to the user created in step 2. The login name and password for the login to be created will be supplied from externally through input parameters. If this procedure executes successfully it returns 0 else 1 to the caller...
0
9673
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9524
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10217
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10168
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10003
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9047
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6785
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5568
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3730
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.