How to declare a variable in MS SQL and use it in the same Stored Procedure
- by Nicklas
Im trying to get the Value from BrandID in one tabel and add it to another tabel. 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