Tengo un procedimiento almacenado donde pregunto por el valor de un parametro y dependiendo de su valor hago el respectivo SELECT
Cita:
Al ejecutar el procedimiento para crearlo no me da errorCREATE PROCEDURE [dbo].spSEARCH_MAS
@Player VARCHAR(10),
@Name VARCHAR(50),
@LastName VARCHAR(50),
@Email VARCHAR(50),
@Password VARCHAR(50),
@Phone VARCHAR(50),
@Zip VARCHAR(50),
@Status CHAR(1)
AS
BEGIN
DECLARE @CREATE_TLB_TEMP NVARCHAR(MAX) -- QUERY TO CREATE THE TEMPORARY TABLE
DECLARE @QUERY_SEARCH NVARCHAR(MAX) -- QUERY THAT PERFORMED THE SEARCHING
IF OBJECT_ID('tempDB..#PlayerTemp','U') IS NOT NULL
DROP TABLE #PlayerTemp;
SET @CREATE_TLB_TEMP = 'SELECT IdPlayer, Player, Name, LastName, Email, Password, IdBook INTO #PlayerTemp FROM PLAYER '
IF (@Status <> 'E' AND @Status <> 'D') BEGIN
SET @CREATE_TLB_TEMP = @CREATE_TLB_TEMP + 'WHERE Player LIKE %'+@Player+'% AND Name LIKE %'+@Name+'%
AND LastName LIKE %'+@LastName+'% AND Email LIKE %'+@Email+'%
AND Password LIKE %'+@Password+'% AND Phone LIKE %'+@Phone+'%
AND Zip LIKE %'+@Zip+'%'
END
ELSE BEGIN
SET @CREATE_TLB_TEMP = @CREATE_TLB_TEMP + 'WHERE Player LIKE %'+@Player+'% AND Name LIKE %'+@Name+'%
AND LastName LIKE %'+@LastName+'% AND Email LIKE %'+@Email+'%
AND Password LIKE %'+@Password+'% AND Phone LIKE %'+@Phone+'%
AND Zip LIKE %'+@Zip+'% AND Status = '+@Status
END
EXEC sp_executesql @CREATE_TLB_TEMP
END
@Player VARCHAR(10),
@Name VARCHAR(50),
@LastName VARCHAR(50),
@Email VARCHAR(50),
@Password VARCHAR(50),
@Phone VARCHAR(50),
@Zip VARCHAR(50),
@Status CHAR(1)
AS
BEGIN
DECLARE @CREATE_TLB_TEMP NVARCHAR(MAX) -- QUERY TO CREATE THE TEMPORARY TABLE
DECLARE @QUERY_SEARCH NVARCHAR(MAX) -- QUERY THAT PERFORMED THE SEARCHING
IF OBJECT_ID('tempDB..#PlayerTemp','U') IS NOT NULL
DROP TABLE #PlayerTemp;
SET @CREATE_TLB_TEMP = 'SELECT IdPlayer, Player, Name, LastName, Email, Password, IdBook INTO #PlayerTemp FROM PLAYER '
IF (@Status <> 'E' AND @Status <> 'D') BEGIN
SET @CREATE_TLB_TEMP = @CREATE_TLB_TEMP + 'WHERE Player LIKE %'+@Player+'% AND Name LIKE %'+@Name+'%
AND LastName LIKE %'+@LastName+'% AND Email LIKE %'+@Email+'%
AND Password LIKE %'+@Password+'% AND Phone LIKE %'+@Phone+'%
AND Zip LIKE %'+@Zip+'%'
END
ELSE BEGIN
SET @CREATE_TLB_TEMP = @CREATE_TLB_TEMP + 'WHERE Player LIKE %'+@Player+'% AND Name LIKE %'+@Name+'%
AND LastName LIKE %'+@LastName+'% AND Email LIKE %'+@Email+'%
AND Password LIKE %'+@Password+'% AND Phone LIKE %'+@Phone+'%
AND Zip LIKE %'+@Zip+'% AND Status = '+@Status
END
EXEC sp_executesql @CREATE_TLB_TEMP
END
Cita:
Pero al ejecutar pasandole los parámetros para hacerlo funcionar como pretendo me da este errorEXEC [dbo].spSEARCH_MAS '','test','','','','','','D'
Msg 156, Level 15, State 1, Line 1
Incorrect syntax near the keyword 'AND'.