1.多條數據使用逗號隔開spa
select invoiceApplyNo,stuff((select distinct ','+incomePlanNo from T1 where a.invoiceApplyNo=invoiceApplyNo for xml path('')),1,1,'') AS items from T1 a group by invoiceApplyNo
2.批量更新多條語句code
方法一xml
update a set HIGH=b.NEW from SPEC1 a,tmpDOT b where a.high=b.old
方法二blog
UPDATE A SET HIGH=B.NEW FROM A LEFT JOIN B ON (A.HIGH=B.OLD)
方法三pdo
update a set high = (select new from tmpdot where old=a.high ) from spec1 a
3.存儲IN查詢處理:字符串
-- ============================================= -- 名稱:字符串分隔成表 -- 維護:ifu25 -- 日期:2018/08/14 -- 說明:用於將相似'1,2,3,4,5,6'的字符串分解成多行,以便於在存儲過程當中使用 where id in(select * from StrSplitToTable(@Strs,',') ) -- ============================================= CREATE function func_StrSplitToTable ( @Strs varchar(max), --須要被分隔的字符串 @Split varchar(50) --分隔符 ) returns @Temp table (id varchar(50) null) as begin while (charindex(@Split, @Strs)<>0) begin insert @Temp(id) values (substring(@Strs, 1, charindex(@Split, @Strs)-1)) set @Strs=stuff(@Strs, 1, charindex(@Split, @Strs), '') end insert @Temp(id) values (@Strs) return end
調用示例:string
SELECT * FROM table_temp id in (SELECT * FROM func_StrSplitToTable(@idStr,','));