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
I can see the following issues with that SP, which may or may not relate to your problem:
)after@BrandNamein yourSELECT(at the end)@CategoryIDor@BrandNameto anything anywhere (they’re local variables, but you don’t assign values to them)In a comment you’ve said that after fixing the
)you get the error:That’s telling you that you haven’t declared any parameters for the SP, but you called it with parameters. Based on your reply about
@CategoryID, I’m guessing you wanted it to be a parameter rather than a local variable. Try this:You would then call this like this:
or this:
…assuming the brand name was ‘Gucci’ and category ID was 23.