首页 > 数据库技术 > 详细

SQL in查询字段为Guid拼接处理办法

时间:2019-05-08 16:24:24      阅读:201      评论:0      收藏:0      [点我收藏+]

 

场景一:在我们写SQL脚本执行普通的Id 为Int,Long 类型查询为 譬如: select *from Table where id in (1,2,3);

 

场景二:SQL in 查询,当查询字段为Guid,或字符串类型时候,需要对In帅选条件进行处理,譬如:select *from Table where GuidID in (‘89e36dd0-4e36-488e-8159-2c56251d7284‘,‘89767f6f-b06b-4081-b6ad-af6b6cf31d64‘) 

可以通过,string.join 进行转换处理。

方法1:strchgPositionTemplateRole = "‘" + string.Join("‘,‘", chgPositionTemplateRole) + "‘";
方法2:string.Join(",", PagePositionTemplateReponse.Select(r => "‘" + r.PositionTemplateID + "‘"))

两者效果一样都可实现;

 

场景三:针对情况,string.join 处理方式,in 条件字符串有可能超过 SQL varchar 设定默认长度

办法一、字符类型改成text ;

办法二、先对SQL语句进行刷选,在用Linq  Contain,Any 等刷选

SQL in查询字段为Guid拼接处理办法

原文:https://www.cnblogs.com/101Love/p/10832326.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!