this question has answer here:
i trying pass string of icd9 codes "where in tsql clause" not work. can below code used few changes? passing table name not appear work either. suggestions appreciated.
declare @startdate datetime declare @enddate datetime declare @icd9 varchar(max) declare @table set @startdate = '2014-01-01 00:00:00' set @enddate = '2015-12-31 23:59:59' set @table = dbo.ipop set @icd9 = '284.1', '284.2', '280.0', '280.1' select x.* @table (select c.id, ip.admitdatetime, ip.icd9code, ip.icd9description dbo.inpatient ip inner join dbo.cohort c on (c.id = ip.id) ip.icd9code in (@icd9) , ip.admitdatetime between @startdate , @enddate union select c.id, op.admitdatetime, op.icd9code, op.icd9description dbo.outpatient op inner join dbo.cohort c on (c.id = op.id) op.icd9code in (@icd9) , op.admitdatetime between @startdate , @enddate ) x order id, admitdatetime go
the short answer cannot pass string delimited list in clause.
please refer erland sommarskog's series of articles on topic alternatives:
Comments
Post a Comment