sqlserver (exists 與 in,查詢結果逗號分割)


sqlserver exists 與 in 的區別

 

使用 EXISTS 方式

select * from A  a where EXISTS(select b.mainInfoId from B b  where b.mainInfoId=a.mainInfoId); 

使用 in  方式
select * from A where id in (select id  from B);

 

sqlserver 將查詢結果以為指定形式分割

#stuff函數

stuff(character_expression,start,length,replaceWith_expression)
刪除指起始位置(start)指定長度(length)的字符,並在該位置插入代替的字符(replaceWith_expression)

 

  #將查詢結果拼接成以逗號分隔的字符串--每條數據以逗號分隔

    
select stuff(( select ','+ requestid from nccombinedpayment for xml path('')),1,1,'') as requestid ;

 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM