Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6135679
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T17:30:30+00:00 2026-05-23T17:30:30+00:00

I have a SPROC let’s call it: AccountExists , with parameter AccountID . I

  • 0

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T17:30:30+00:00Added an answer on May 23, 2026 at 5:30 pm

    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 @AccountExists what is as you can see quite overkill.

    CREATE PROCEDURE AccountExists
      @AccountID INT,
      @AccountExists BIT OUTPUT
    AS
    BEGIN
      IF NOT EXISTS (SELECT * FROM dbo.Accounts WHERE AccountID = @AccountID)
        SET @AccountExists = 0
      ELSE
        SET @AccountExists = 1
    END
    
    CREATE PROCEDURE CreateAccount
      @AccountID INT
    AS
    BEGIN
      DECLARE @AccountExists BIT
      EXEC AccountExists @AccountID, @AccountExists OUT
    
      IF NOT @AccountExists
        INSERT INTO dbo.Accounts (AccountID, AccountName) VALUES ...    
    END
    

    The second example uses user defined function what is IMHO what you have tried to iplie in your question.

    CREATE FUNCTION AccountExists
      (@AccountID INT)
    RETURNS BIT
    AS
    BEGIN
      IF NOT EXISTS (SELECT * FROM dbo.Accounts WHERE AccountID = @AccountID)
        RETURN 0
      ELSE
        RETURN 1
    END
    
    CREATE PROCEDURE CreateAccount
      @AccountID INT
    AS
    BEGIN      
      IF SELECT AccountExists(@AccountID) = 0
        INSERT INTO dbo.Accounts (AccountID, AccountName) VALUES ...    
    END
    

    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.

    CREATE PROCEDURE CreateAccount
      @AccountID INT
    AS
    BEGIN      
      IF NOT EXISTS (SELECT * FROM dbo.Accounts WHERE AccountID = @AccountID)
        INSERT INTO dbo.Accounts (AccountID, AccountName) VALUES ...    
    END
    

    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 🙂

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

so I have a sproc in a db.. lets call this db A .
I have two queries being returned by my sproc. I want to be able
I have a single int output parameter for a sproc in MSSQL 2008. The
Let's say that I have an article on a website, and I want to
I have a delimiter string like this: 2,3 which is grabbed from a listbox
Let's assume we have this very simple table: |class |student| --------------- Math Alice Math
I have a SPROC that runs every hour. This SPROC calculates the popularity of
I have a sproc that returns a single line and column with a text,
I have seen various rules for naming stored procedures. Some people prefix the sproc
Have you managed to get Aptana Studio debugging to work? I tried following this,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.