How to remove quotes from variable

barnesco
barnesco used Ask the Experts™
on
How do I remove the '' from the UserID variable so that I can return the below statement:

DECLARE
@UserID varchar(max)='13,28'

SELECT UserID FROM Users WHERE CAST(UserID AS varchar(20)) IN (@UserID)

@UserID = '13,28' does not work but @UserID = 13,28 does.
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®

Commented:
use the replace command

Commented:
@UserID varchar(max)= REPLACE(@strip, '13,28', '')
Database Administrator
Top Expert 2005
Commented:
You would have to use dynamic sql:

DECLARE @EmpID AS NVARCHAR(50)
DECLARE @SQLQuery AS NVARCHAR(500)

/* Build and Execute a Transact-SQL String with a single
parameter value Using sp_executesql Command */
SET @EmpID = '1001,1003'
SET @SQLQuery = 'SELECT * FROM tblEmployees
WHERE EmployeeID IN(' + @EmpID + ')'
EXECUTE sp_executesql @SQLQuery

Author

Commented:
Thanks, that worked great.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial