DECLARE @MedicalInstitutionID NVARCHAR(100)='SYS20130228000000012'; SELECT ',' + MedicineTypeID FROM Dic_Res_StoreToType b WHERE b.MedicalInstitutionID = @MedicalInstitutionID FOR XML PATH('')