user222427
user222427

Reputation:

mysql declaring and setting variables. syntax errors

I thought this would be a simple task but i cannot figure out why this gives me an error in my syntax. Any help is appreciated.

DECLARE @usernameid VARCHAR(20);
declare @UserIDParam VARCHAR(20);
SET @usernameid = 'myid';
SET @UserIDParam =
   (SELECT userid
      FROM tblusers
     WHERE unid = usernameid);

SELECT *
 FROM tblusers
 WHERE tblusers.userID = @useridparam

Upvotes: 0

Views: 505

Answers (1)

eggyal
eggyal

Reputation: 125945

One doesn't DECLARE user variables: one just uses them. (You DECLARE local variables e.g. in a procedure).

Upvotes: 1

Related Questions