Click here to Skip to main content
15,890,845 members
Home / Discussions / Database
   

Database

 
QuestionWhich SQL server to install on Novel network server Pin
supportks13-Jun-09 1:51
supportks13-Jun-09 1:51 
AnswerRe: Which SQL server to install on Novel network server Pin
Henry Minute13-Jun-09 6:12
Henry Minute13-Jun-09 6:12 
Questionhow to get data from Server A to Server B Pin
Satish_S12-Jun-09 18:30
Satish_S12-Jun-09 18:30 
AnswerRe: how to get data from Server A to Server B Pin
Mycroft Holmes13-Jun-09 2:33
professionalMycroft Holmes13-Jun-09 2:33 
Questionproblem in sql server connection Pin
pampam11012-Jun-09 6:40
pampam11012-Jun-09 6:40 
AnswerRe: problem in sql server connection Pin
Jerry Hammond12-Jun-09 10:13
Jerry Hammond12-Jun-09 10:13 
GeneralRe: problem in sql server connection Pin
pampam11015-Jun-09 22:24
pampam11015-Jun-09 22:24 
QuestionStored Procedure with complex(ish) IF.....ELSE Pin
munklefish12-Jun-09 4:02
munklefish12-Jun-09 4:02 
Hi,

Thanks to a massively helpful ROb ive manged to learn a little about conditional statements in Stored Procedures. However i have now created the following SP and it gives an error when compiling.

Incorrect syntax near the keyword 'ELSE'

CREATE PROCEDURE web.createDefaultAddressBook
       (
       @tmp_custID bigint,
       @tmp_Description varchar(500),
       @tmp_NoRecipients bigint,
       @tmp_Email varhar(100),
       @tmp_Forename varchar(100),
       @tmp_Surname varchar(100)
       )
AS
BEGIN
       declare @key bigint
       declare @newSignUpID bigint
       --determine id of record if exists
       SELECT @key = addMaster_Key FROM tbl_AddressBookMaster WHERE addMaster_UserId = @tmp_custID AND addMaster_Title = 'Default'

       IF @key IS null
       --address book doesnt exist just so create default
       
       INSERT INTO tbl_AddressBookMaster ([addMaster_UserId], [addMaster_Title], [addMaster_Description], [addMAster_NoRecipients])
       VALUES (@tmp_custID, 'Default', @tmp_Description, 0)
       SELECT @newSignUpID = SCOPE_IDENTITY()
       
      --add addresses to second table
       INSERT INTO tbl_AddressBookAddresses ([adds_ABMId], [adds_Email], [adds_RecipientForename], [adds_RecipientSurname])
       VALUES (@newSignUpID, @tmp_Email, @tmp_Forename, @tmp_Surname)

       ELSE
       --default already exists
       
       --add addresses to second table
       INSERT INTO tbl_AddressBookAddresses ([adds_ABMId], [adds_Email], [adds_RecipientForename], [adds_RecipientSurname])
       VALUES (@key, @tmp_Email, @tmp_Forename, @tmp_Surname)
END


What am i doing wrong?

Is there a more efficient way to do this considering i will be using it in code which will loop through a huge array and pass new records into the SP?

Effective but simple is probably best at this stage though.

Thanks in advance.
AnswerRe: Stored Procedure with complex(ish) IF.....ELSE Pin
Blue_Boy12-Jun-09 4:12
Blue_Boy12-Jun-09 4:12 
QuestionRe: Stored Procedure with complex(ish) IF.....ELSE Pin
munklefish12-Jun-09 4:18
munklefish12-Jun-09 4:18 
AnswerRe: Stored Procedure with complex(ish) IF.....ELSE Pin
Rob Philpott12-Jun-09 4:22
Rob Philpott12-Jun-09 4:22 
AnswerRe: Stored Procedure with complex(ish) IF.....ELSE Pin
munklefish12-Jun-09 4:16
munklefish12-Jun-09 4:16 
AnswerRe: Stored Procedure with complex(ish) IF.....ELSE Pin
Rob Philpott12-Jun-09 4:20
Rob Philpott12-Jun-09 4:20 
GeneralRe: Stored Procedure with complex(ish) IF.....ELSE Pin
munklefish12-Jun-09 4:35
munklefish12-Jun-09 4:35 
AnswerRe: Stored Procedure with complex(ish) IF.....ELSE Pin
Niladri_Biswas17-Jun-09 20:55
Niladri_Biswas17-Jun-09 20:55 
QuestionStored procedure across multiple servers? Pin
enipla12-Jun-09 3:13
enipla12-Jun-09 3:13 
AnswerRe: Stored procedure across multiple servers? Pin
saanj12-Jun-09 3:16
saanj12-Jun-09 3:16 
GeneralRe: Stored procedure across multiple servers? Pin
enipla12-Jun-09 3:41
enipla12-Jun-09 3:41 
GeneralRe: Stored procedure across multiple servers? Pin
enipla12-Jun-09 3:47
enipla12-Jun-09 3:47 
AnswerRe: Stored procedure across multiple servers? Pin
Abhijit Jana12-Jun-09 3:53
professionalAbhijit Jana12-Jun-09 3:53 
GeneralRe: Stored procedure across multiple servers? Pin
enipla12-Jun-09 4:00
enipla12-Jun-09 4:00 
GeneralRe: Stored procedure across multiple servers? Pin
Abhijit Jana12-Jun-09 4:15
professionalAbhijit Jana12-Jun-09 4:15 
GeneralRe: Stored procedure across multiple servers? Pin
enipla12-Jun-09 5:11
enipla12-Jun-09 5:11 
AnswerRe: Stored procedure across multiple servers? Pin
Jerry Hammond12-Jun-09 4:42
Jerry Hammond12-Jun-09 4:42 
AnswerRe: Stored procedure across multiple servers? Pin
enipla12-Jun-09 6:38
enipla12-Jun-09 6:38 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.