How to declare a variable in SQL Server and use it in the same Stored Procedure

Posted by Nicklas on Stack Overflow See other posts from Stack Overflow or by Nicklas
Published on 2010-05-08T08:10:29Z Indexed on 2010/05/08 12:58 UTC
Read the original article Hit count: 268

Im trying to get the value from BrandID in one table and add it to another table. But I can't get it to work. Anybody know how to do it right?

CREATE PROCEDURE AddBrand
AS

DECLARE 
@BrandName nvarchar(50),
@CategoryID int,
@BrandID int

SELECT @BrandID = BrandID FROM tblBrand 
WHERE BrandName = @BrandName

INSERT INTO tblBrandinCategory (CategoryID, BrandID) 
       VALUES (@CategoryID, @BrandID) 

RETURN

© Stack Overflow or respective owner

Related posts about sql-server

Related posts about local-variable