//先声明
DECLARE @BARANDID VARCHAR(100)
patindex 用法,例如 YHBH =10,20,30 如果 我要单独值查询满足20条件的记录呢?SFRBH=20
SET @BARANDID= (SELECT YHBH FROM SKJBXX_FPBHQD WHERE YLJGBH=@YLJGBH AND patindex('%,"+SFRBH+",%',',' + YHBH + ',' )>0 )
还可以使用临时表 功能
CREATE TABLE #temp1
(
CFBHs VARCHAR(8000)
)
INSERT INTO #temp1 SELECT cfbh from MZ_CFJLB WHERE YLJGBH=@YLJGBH AND MZBH=@MZBH
select * from tb where in (select * from #temp1)