my question is how to compare in the if, the variable that I created called @name with the attribute of the table called Name?
It's really quite simple:
IF EXISTS(SELECT 1 FROM Sales.Store WHERE Name = @name)
BEGIN
SELECT '[nombre de tienda existente]';
END
ELSE
BEGIN
INSERT INTO Sales.Store
VALUES(@entityID, @name, @salespersonID, @demographics, @rowguid, @modifieddate);
END
Next time, please post the code inside the question, instead of an image.
Two other alternatives to be taken into account to take care of the consistency of the data, especially if this sp is not the only point of data entry to it:
1) Create a unique constraint on the Name field of the Sales.Store table
ALTER TABLE Sales.Store ADD CONSTRAINT UK_Name UNIQUE (Name)
And then handle the error with a Try Catch Block.
2) Create a trigger on the table to control that the Name value does not repeat