一个变量赋值的问题
语句如下:
DECLARE @companyid VARCHAR (100)
SET @companyid='102,103,106,107,108'
SELECT * FROM oCompany WHERE CompanyID IN (@companyid)
DECLARE @companyid VARCHAR(100),@tsql varchar(6000)
SET @companyid='102,103,106,107,108'
select @tsql='SELECT * FROM oCompany WHERE CompanyID IN ('+@companyid+')'
exec(@tsql)
DECLARE @companyid VARCHAR (100)
SET @companyid='102,103,106,107,108'
SELECT *
FROM oCompany
WHERE charindex(CompanyID, @companyid ) > 0