next I want to do the same thing in the SW_REQUEST table. If there is a record in there for the member, I want to just skip the insert.
My code works as long as there isn't an existing record in the tables. Can someone give me a hand?
Here's what I have (and it doesn't work)
It looks like you are doing a RETURN if the record is not found in the MEMBERS table, so that the check of the SW_REQUESTS table never happens.
CREATE PROCEDURE b4b_sw_request@.FName as varchar(50)= NULL,
@.LName as varchar(50)=NULL,
@.Address1 as varchar(100) = NULL,
@.Address2 as varchar(100) = NULL,
@.City as varchar(50) = NULL,
@.State as char(2) = NULL,
@.Zip as char(5) = NULL,
@.Email as varchar(100) = NULL,
@.Send_Updates as smallint = '0'AS
IF EXISTS
(SELECT FName, LName, Address1, Zip from MEMBERS WHERE FName = @.FName AND LName = @.LName AND Zip = @.Zip)
BEGIN
RETURN
ENDELSE
BEGIN
INSERT INTO MEMBERS
(FName, LName, Address1, Address2, City, State, Zip, Email)
Values
(@.FName, @.LName, @.Address1, @.Address2, @.City, @.State, @.Zip, @.Email)
ENDIF EXISTS
(SELECT MEMBER_ID FROM SW_REQUESTS WHERE MEMBER_ID = @.@.Identity)
BEGIN
RETURN
ENDELSE
BEGIN
INSERT INTO SW_REQUESTS
(MEMBER_ID, Send_Updates)
Values
(@.@.Identity, @.Send_Updates)
END
GO
You might need this instead:
IF NOT EXISTS (SELECT FName, LName, Address1, Zip from MEMBERS WHERE FName = @.FName AND LName = @.LName AND Zip = @.Zip)
BEGIN
INSERT INTO MEMBERS
(FName, LName, Address1, Address2, City, State, Zip, Email)
Values
(@.FName, @.LName, @.Address1, @.Address2, @.City, @.State, @.Zip, @.Email)
ENDIF NOT EXISTS (SELECT MEMBER_ID FROM SW_REQUESTS WHERE MEMBER_ID = @.@.Identity)
BEGIN
INSERT INTO SW_REQUESTS
(MEMBER_ID, Send_Updates)
Values
(@.@.Identity, @.Send_Updates)
END
Terri|||Thanks Terri.
I was thinking that the return stopped the logic and jumped to the next IF statement. I didn't realize it put the breaks on everything ;-)
No comments:
Post a Comment