06/11/2013, 19:42
|
| | | Fecha de Ingreso: septiembre-2012
Mensajes: 450
Antigüedad: 12 años, 3 meses Puntos: 3 | |
Problemas con IF ELSE en SQL-SERVER Hola y saludos,
Tengo un procedimiento almacenado donde pregunto por el valor de un parametro y dependiendo de su valor hago el respectivo SELECT Cita: CREATE 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 Al ejecutar el procedimiento para crearlo no me da error Cita: EXEC [dbo].spSEARCH_MAS '','test','','','','','','D' Pero al ejecutar pasandole los parámetros para hacerlo funcionar como pretendo me da este error Msg 156, Level 15, State 1, Line 1
Incorrect syntax near the keyword 'AND'. |