I have a SPROC let’s call it: AccountExists, with parameter AccountID. I have another SPROC let’s call this one: CreateAccount.
I want to call the AccountExists from the CreateAccount, and pass the AccountID along. Sort of like this:
IF NOT EXISTS (AccountExists(AccountID))
BEGIN
INSERT INTO dbo.Accounts
(AccountID,
AccountName)
END
If you are able to follow the logic I want a create account SPROC that will call the check to see if the account already exists.
I’m not sure if I understood your question correctly, but I’ll try to post the answer.
The first example here uses the stored procedure with the output parameter will return the result into the boolean variable
@AccountExistswhat is as you can see quite overkill.The second example uses user defined function what is IMHO what you have tried to iplie in your question.
And finally the third example uses simple inlined test for value existence. I don’t know how complicated (and how frequent in your code) will your account existence verification be, so this way might be uncomfortable for you a bit.
I’m not sure if that’s what you were looking for. Also please note that it’s quite a long time I’ve worked with TSQL, so if it’s wrong then beat me up 🙂