Stored Procedure

  • I don't understand why I am getting this message when I run my stored procedure.

    Syntax error converting the varchar value 'IdentityCol' to a column of data type int.

    This is my stored procedure:

    ALTER PROCEDURE Login

    (

    @UserName Varchar( 20 ),

    @Password Varchar( 20 )

    )

    AS

    DECLARE @user-id INT

    Set @user-id = 'IdentityCol'

    SELECT Count (*) FROM dbo.User_Information WHERE User_Name=@UserName AND Password =@Password

    Return @user-id

    I don't see why it thinks the IdentityCol is varchar it is set up as a Int in the table?

    I am just trying to validate a user based on the UserName and password and if it is valid then return the IdentityCol.

    I am stuck so any help is greatly appreciated

  • Set @user-id = 'IdentityCol' means that you are trying to assign the string 'IdentityCol' as a value of @userid. It is enclosed in single quotes. If you wanted to assign a value of the column IdentityCol from some table, it should be something like

    SELECT @userid = IdentityCol

    FROM dbo.User_Information

    WHERE User_Name = @UserName AND Password = @Password

    What should the COUNT(*) do, I'm not sure... it isn't defined as a condition, and it doesn't influence the result of procedure in any way. If no such user and password combination exists in the table, @userid remains NULL - no need to check the count additionally, and if the table is correctly designed, it should never allow duplicate user names... so you don't have to be afraid of several matching rows.

    BTW, I never tried to use the IDENTITYCOL keyword, so I'm not sure whether it will work in this context. Why not use the name of the column?? IMHO it is much better to be as explicit as possible.

    HTH, Vladan

Viewing 2 posts - 1 through 1 (of 1 total)

You must be logged in to reply to this topic. Login to reply