Tengo el siguiente procedimiento almacenado...
Cita:
El problema que tengo es que los IF que estoy haciendo para validar algunas cosas no esta funcionando y al ejecutar el procedimiento me da el siguiente error:CREATE PROCEDURE [dbo].[spTABLE_TEMPORARY_PLAYER]
@Player VARCHAR(10),
@Name VARCHAR(50),
@LastName VARCHAR(50),
@Email VARCHAR(50),
@Password VARCHAR(50),
@Phone VARCHAR(50),
@Zip VARCHAR(50),
@Status CHAR(1),
@LoginDateStart VARCHAR(25),
@LoginDateEnd VARCHAR(25),
@Ip VARCHAR(15),
@WebSite INT,
@Success CHAR(1)
AS
BEGIN
IF OBJECT_ID('tempDB..#PlayerTemp','U') IS NOT NULL
DROP TABLE #PlayerTemp;
DECLARE @StatusAux VARCHAR
DECLARE @WebsiteAux INT
DECLARE @SuccessAux CHAR(1)
IF @Status <> ''
SET @StatusAux = 'AND Status = ' + @Status
ELSE
SET @StatusAux = ''
SELECT IdPlayer, Player, Name, LastName, Email, Password, IdBook
INTO #PlayerTemp
FROM PLAYER
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 + '' + @StatusAux
IF @WebSite <> 0
SET @WebsiteAux = 'AND B.[id] = ' + @WebSite
ELSE
SET @WebsiteAux = ''
IF @Success <> 'Y' AND @Success <> 'N'
SET @SuccessAux = ''
ELSE
SET @SuccessAux = ' AND L.[success] = '+ @Success
SELECT TOP 10000 P.[IdPlayer], P.[Player], L.[username], L.[password], L.[ip_address], L.[login_date],
L.[success],D.[Description], B.[host_name],
P.[Name] + ' ' + P.[LastName] AS 'Name', P.Email
FROM [BackOffice_Dev].[dbo].[login] L, [dbo].[#PlayerTemp] P, BOOK D, [BackOffice_Dev].[dbo].[book] B
WHERE D.[IdBook] = P.[IdBook] AND L.[book_id] = B.[book_id] AND D.[IdBook] = L.[book_id]
AND P.[player] = L.[username] AND B.[id] = L.[website_id]
AND L.[login_date] >= convert(datetime,(@LoginDateStart))
AND L.[login_date] <= convert(datetime,(@LoginDateEnd))
AND L.[ip_address] LIKE @Ip + @WebsiteAux + @SuccessAux
ORDER BY L.[login_date] DESC
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),
@LoginDateStart VARCHAR(25),
@LoginDateEnd VARCHAR(25),
@Ip VARCHAR(15),
@WebSite INT,
@Success CHAR(1)
AS
BEGIN
IF OBJECT_ID('tempDB..#PlayerTemp','U') IS NOT NULL
DROP TABLE #PlayerTemp;
DECLARE @StatusAux VARCHAR
DECLARE @WebsiteAux INT
DECLARE @SuccessAux CHAR(1)
IF @Status <> ''
SET @StatusAux = 'AND Status = ' + @Status
ELSE
SET @StatusAux = ''
SELECT IdPlayer, Player, Name, LastName, Email, Password, IdBook
INTO #PlayerTemp
FROM PLAYER
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 + '' + @StatusAux
IF @WebSite <> 0
SET @WebsiteAux = 'AND B.[id] = ' + @WebSite
ELSE
SET @WebsiteAux = ''
IF @Success <> 'Y' AND @Success <> 'N'
SET @SuccessAux = ''
ELSE
SET @SuccessAux = ' AND L.[success] = '+ @Success
SELECT TOP 10000 P.[IdPlayer], P.[Player], L.[username], L.[password], L.[ip_address], L.[login_date],
L.[success],D.[Description], B.[host_name],
P.[Name] + ' ' + P.[LastName] AS 'Name', P.Email
FROM [BackOffice_Dev].[dbo].[login] L, [dbo].[#PlayerTemp] P, BOOK D, [BackOffice_Dev].[dbo].[book] B
WHERE D.[IdBook] = P.[IdBook] AND L.[book_id] = B.[book_id] AND D.[IdBook] = L.[book_id]
AND P.[player] = L.[username] AND B.[id] = L.[website_id]
AND L.[login_date] >= convert(datetime,(@LoginDateStart))
AND L.[login_date] <= convert(datetime,(@LoginDateEnd))
AND L.[ip_address] LIKE @Ip + @WebsiteAux + @SuccessAux
ORDER BY L.[login_date] DESC
END
Cita:
Eso quiere decir que si me crea la tabla temporal pero el segundo select me esta fallando, alguna ayuda al respecto ? (31 row(s) affected)
Msg 245, Level 16, State 1, Procedure spTABLE_TEMPORARY_PLAYER, Line 47
Conversion failed when converting the varchar value '%%' to data type int.
Msg 245, Level 16, State 1, Procedure spTABLE_TEMPORARY_PLAYER, Line 47
Conversion failed when converting the varchar value '%%' to data type int.