Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Need help with Stored Procedure Syntax

Status
Not open for further replies.

Cenedra

Programmer
Jan 2, 2003
114
US
I've got this stored procedure, and I know it is wrong, but am not sure how to make it right.

CREATE PROCEDURE [dbo].[sp_CreateNewConnection]

(
@UserID int = NULL,
@FriendID varchar = NULL
)
AS
INSERT INTO CONNECTIONS (userid, friendid)
values (@UserID, (select id from users where username = @FriendUserName))

Can anyone show me how to do what I'm really trying to do here?

Much thanks
Cen

 
@FriendID should really be @FriendUserName in the variable declaration section, btw.

 
Code:
CREATE PROCEDURE dbo.CreateNewConnection
(
    @UserID int = NULL,
    @FriendUserName varchar(30) = NULL
)
AS
    INSERT INTO CONNECTIONS (userid, friendid)
    select @UserID, id 
      from users 
     where username = @FriendUserName

You shouldn't name your procedures with the prefix sp_
Yuo must supply the maximum length for the varchar otherwise it defaults to 1
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top