Question表与Paper表
Paper表中字段QuestionIds存储的是Question表中字段Id的拼接后的值
如: 'f855eba1-b308-4bd7-a250-c071a0e1bdf0','c0570880-931b-4b34-ba34-58937f940c21','96249256-ddd7-4b28-a066-ebe1c337cf6c','c0b6171a-1b50-4881-a5f5-9928ce1bf593','b71ad813-abad-40f2-bf97-a1ae998acbc8','b7eec3b6-70d0-41c3-8fc0-c8aba71148f2','be2eedb6-d56c-40e8-b21c-1a7b903192c4','16c8697a-17c3-4e27-84c7-7416eea8ac21','6bdfbed9-1960-47dc-9fb5-2ea56005dcda','fdb0a4ab-5a8d-4601-a962-fa32b1a1e78c'
QuestionIds作为Question表的In查询条件:先声明一个变量用来存储查询出来的QuestionIds,然后用函数exec执行查询
declare @idlist varchar(2000) select @idlist = QuestionIds from Paper where Id='3714426E-0D7C-45C9-A3BC-60D3F1D6EFCD' exec('select * from Question where Id in(' + @idlist + ')')