troubleshooting Question

Advice on Stored Procedure - Does my Stored Procedure still return data?

Avatar of rito1
rito1 asked on
SQL
3 Comments2 Solutions254 ViewsLast Modified:
Hi All

What I am wanting to do is insert a new record if the record doesn't already exist. I have the following stored procedure and my question is very minor but will niggle me if I don't ask...

Though I am not actually wanting the data from my SELECT statement to be returned to my application does it anyway?... you will see that I am just wanting to use the SELECT statement to find out whether to run the INSERT statement.

CREATE PROCEDURE [dbo].[INSERTUser]

      @uname Int,
      @pword Int

AS

SELECT uname FROM tbluser
WHERE
      uname = @uname AND
      pword = @pword

IF @@ROWCOUNT = 0

BEGIN
INSERT INTO tbluser
(
      uname,
      pword
)
VALUES
(
      @uname,
      @pword
)
END
GO

Many thanks

Rit
ASKER CERTIFIED SOLUTION
Aneesh
Database Consultant
Join our community to see this answer!
Unlock 2 Answers and 3 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 2 Answers and 3 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros