Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
Deezy1017
Starting Member
4 Posts |
Posted - 2013-10-05 : 22:20:46
|
I am trying to do a rollback but am having error at this block of codebegin transaction revisit_loyalt declare @i varchar(40) set @i='Clarendon' if ((select COUNT(parsh) as parish_count from client where parish=@i)<5) begin insert into client values (100,'Shauna','Smith','Clarendon') insert into loyalty_card values (101,100) end else begin // this is the line giving trouble ROLLBACK revisit_loyalt endS.Davis |
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2013-10-06 : 03:28:31
|
[code]BEGIN TRANSACTION;DECLARE @i VARCHAR(40) = 'Clarendon';IF (SELECT COUNT(parsh) FROM dbo.Client WHERE Parish = @i) < 5 BEGIN INSERT dbo.Client VALUES (100, 'Shauna', 'Smith', 'Clarendon'); INSERT dbo.Loyalty_Card VALUES (101, 100) COMMIT TRANSACTION ENDELSE BEGIN ROLLBACK TRANSACTION END;[/code] Microsoft SQL Server MVP, MCT, MCSE, MCSA, MCP, MCITP, MCTS, MCDBA |
|
|
Deezy1017
Starting Member
4 Posts |
Posted - 2013-10-06 : 11:15:12
|
hey thanks is it because am dealing with transaction why I refer directly to the database?S.Davis |
|
|
James K
Master Smack Fu Yak Hacker
3873 Posts |
Posted - 2013-10-06 : 17:16:22
|
quote: Originally posted by Deezy1017 hey thanks is it because am dealing with transaction why I refer directly to the database?S.Davis
You are not referring to the database explicitly anywhere in your code or in the code that Swepeso posted, as far as I can tell. So it assumes that your current database is the database that you want to work with.If that did not answer your question, can you clarify what you meant by "refer directly to the database"? |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2013-10-07 : 05:50:08
|
quote: Originally posted by Deezy1017 hey thanks is it because am dealing with transaction why I refer directly to the database?S.Davis
what was the actual error message you got ?------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/https://www.facebook.com/VmBlogs |
|
|
|
|
|
|
|