This is wierd. I am trying to use a variable for the where clause in an SP. I am using EXEC (for now) to execute a built string of SQL. This part breaks it:
@UID is a parameter - VARCHAR(10)
Here is the error I am getting:
Conversion failed when converting the varchar value ' r.creator = 'SYS.LJW' ' to data type int.
I don't understand why SQL Server is trying to convert that to an INT.
Thanks!
Code:
DECLARE @WHERE_SQL AS VARCHAR(500)
IF @STATUS = 'ALL'
SET @WHERE_SQL = ' r.creator = ''' + @UID + ''' '
ELSE
SET @WHERE_SQL = ' WHERE s.[Status] = ''' + @STATUS + ''' AND r.creator = ''' + @UID + ''''
SET @COUNT = ( SELECT COUNT(r.ereq)
FROM dbo.Request r
INNER JOIN dbo.[Status] s ON s.ereq = r.ereq + ' ' + @WHERE_SQL
)
@UID is a parameter - VARCHAR(10)
Here is the error I am getting:
Conversion failed when converting the varchar value ' r.creator = 'SYS.LJW' ' to data type int.
I don't understand why SQL Server is trying to convert that to an INT.
Thanks!