Reputation: 393
Can anyone please point out what im doing wrong with this Stored Procedure please. I cant get it to compile and my software isnt giving any useful clues as to what is wrong with it.
CREATE PROCEDURE web.createSubscriptions
(
@Member_Id BIGINT,
@Trans_type VARCHAR(100),
@Payment_Status VARCHAR(100),
@Payment_Date DATETIME,
@Trans_Id VARCHAR(100)
)
AS
DECLARE @tmpType VARCHAR(15)
BEGIN
INSERT INTO TBL_SUBSCRIPTIONS (subs_MemberID, subs_Type, subs_Status, subs_DateGenerated, subs_PaypalTransaction) VALUES(@Member_Id, @Trans_Type, @Payment_Status, @Payment_Date, @Trans_Id)
IF(@Trans_type = 'subscr_signup')
BEGIN
@tmpType = 'premium'
END
ELSE(@Trans_type = 'subscr_cancel')
BEGIN
@tmpType = 'basic'
END
UPDATE TBL_MEMBERS
SET members_Type = @tmpType
WHERE members_Id = @Member_Id
END
Upvotes: 15
Views: 116094
Reputation: 3183
Try this with SQL join statements
CREATE PROCEDURE [dbo].[deleteItem]
@ItemId int = 0
AS
Begin
DECLARE @cnt int;
SET NOCOUNT ON
SELECT @cnt =COUNT(ttm.Id)
from ItemTransaction itr INNER JOIN ItemUnitMeasurement ium
ON itr.Id = ium.ItemTransactionId INNER JOIN ItemMaster im
ON itr.ItemId = im.Id INNER JOIN TransactionTypeMaster ttm
ON itr.TransactionTypeMasterId = ttm.Id
where im.Id = @ItemId
if(@cnt = 1)
Begin
DECLARE @transactionType varchar(255);
DECLARE @mesurementAmount float;
DECLARE @itemTransactionId int;
DECLARE @itemUnitMeasurementId int;
SELECT @transactionType = ttm.TransactionType, @mesurementAmount = ium.Amount, @itemTransactionId = itr.Id, @itemUnitMeasurementId = ium.Id
from ItemTransaction itr INNER JOIN ItemUnitMeasurement ium
ON itr.Id = ium.ItemTransactionId INNER JOIN TransactionTypeMaster ttm
ON itr.TransactionTypeMasterId = ttm.Id
where itr.ItemId = @ItemId
if(@transactionType = 'Close' and @mesurementAmount = 0)
Begin
delete from ItemUnitMeasurement where Id = @itemUnitMeasurementId;
End
else
Begin
delete from ItemTransaction where Id = @itemTransactionId;
End
End
else
Begin
delete from ItemMaster where Id = @ItemId;
End
END
Upvotes: 0
Reputation: 5834
Just a tip for this, you don't need the BEGIN and END if it only contains a single statement.
ie:
IF(@Trans_type = 'subscr_signup')
set @tmpType = 'premium'
ELSE iF(@Trans_type = 'subscr_cancel')
set @tmpType = 'basic'
Upvotes: 0
Reputation: 1444
try
IF(@Trans_type = 'subscr_signup')
BEGIN
set @tmpType = 'premium'
END
ELSE iF(@Trans_type = 'subscr_cancel')
begin
set @tmpType = 'basic'
END
Upvotes: -1
Reputation: 29157
Nick is right. The next error is the else should be else if (you currently have a boolean expression in your else which makes no sense). Here is what it should be
ELSE IF(@Trans_type = 'subscr_cancel')
BEGIN
SET @tmpType = 'basic'
END
You currently have the following (which is wrong):
ELSE(@Trans_type = 'subscr_cancel')
BEGIN
SET @tmpType = 'basic'
END
Here's a tip for the future- double click on the error and SQL Server management Studio will go to the line where the error resides. If you think SQL Server gives cryptic errors (which I don't think it does), then you haven't worked with Oracle!
Upvotes: 17
Reputation: 29659
yeah Nick is right.
You need to use SET
or SELECT
to assign to @tmpType
Upvotes: 1
Reputation: 7966
Are you missing the 'SET' statement when assigning to your variables in the IF .. ELSE block?
Upvotes: 3
Reputation: 1718
It isn't giving any errors?
Try
SET @tmpType = 'premium
'
and
SET @tmpType = 'basic'
Upvotes: 8