Reputation:
Basically, i'm going to be passing my parameter SystemFeedbackidParam
if SystemFeedbackidParam is not null, do one thing, if it is, then do the seperate thing. I can do this in SQL but the way to do this is mysql is eluding me.
Thanks!
CREATE PROCEDURE `_Insert_FeedBack`( FeedbackTypeParam varchar(20), FeedbackSubjectParam varchar(200), FeedbackTextParam text, FeedbackHTMLParam longtext, SubmittedByParam varchar(20), SubmittedDateParam datetime, SystemFeedbackidParam int) BEGIN IF (SystemFeedbackidParam IS NOT NULL) THEN --/*Insert Child Record into tblfeedbackitems */ INSERT INTO tblfeedbackitems(SystemFeedbackId, FeedbackType, FeedbackText, FeedbackHTML, SubmittedBy, SubmittedDate) VALUES (SystemFeedbackidParm, FeedbackTypeParam , FeedbackTextParam , FeedbackHTMLParam , SubmittedByParam , SubmittedDateParam ); ELSE --/*Insert Parent Record into tblFeedback */ INSERT INTO tblfeedback( FeedbackType, FeedbackSubject, FeedbackStatus) VALUES ( FeedbackTypeParam, FeedbackSubjectParam, 'Open'); --/*Insert Child Record into tblFeedback */ INSERT INTO tblfeedbackitems(SystemFeedbackId, FeedbackType, FeedbackText, FeedbackHTML, SubmittedBy, SubmittedDate) VALUES (LAST_INSERT_ID(), FeedbackTypeParam , FeedbackTextParam , FeedbackHTMLParam , SubmittedByParam , SubmittedDateParam ); END
Upvotes: 0
Views: 40
Reputation:
You have several problems here:
Try this:
Delimiter $$
CREATE PROCEDURE `_Insert_FeedBack`(
FeedbackTypeParam varchar(20),
FeedbackSubjectParam varchar(200),
FeedbackTextParam text,
FeedbackHTMLParam longtext,
SubmittedByParam varchar(20),
SubmittedDateParam datetime,
SystemFeedbackidParam int)
BEGIN
IF (SystemFeedbackidParam IS NOT NULL)
THEN
-- /*Insert Child Record into tblfeedbackitems */
INSERT INTO tblfeedbackitems(SystemFeedbackId,
FeedbackType,
FeedbackText,
FeedbackHTML,
SubmittedBy,
SubmittedDate)
VALUES (SystemFeedbackidParm,
FeedbackTypeParam
,
FeedbackTextParam
,
FeedbackHTMLParam
,
SubmittedByParam
,
SubmittedDateParam
);
ELSE
-- /*Insert Parent Record into tblFeedback */
INSERT INTO tblfeedback(
FeedbackType,
FeedbackSubject,
FeedbackStatus)
VALUES (
FeedbackTypeParam,
FeedbackSubjectParam,
'Open');
-- /*Insert Child Record into tblFeedback */
INSERT INTO tblfeedbackitems(SystemFeedbackId,
FeedbackType,
FeedbackText,
FeedbackHTML,
SubmittedBy,
SubmittedDate)
VALUES (LAST_INSERT_ID(),
FeedbackTypeParam
,
FeedbackTextParam
,
FeedbackHTMLParam
,
SubmittedByParam
,
SubmittedDateParam
);
END IF;
END $$
Delimiter ;
Note: I've fixed your syntax errors. I have no idea whether your code will actually work.
Upvotes: 1
Reputation: 153
check the documentation of mysql on this site http://dev.mysql.com/doc/refman/5.0/en/if.html there you can find all the info, but basically is like this
IF NOT SystemFeedbackidParam THEN
......
END IF;
also you can use the else statement.
Upvotes: 0