本文介绍了SQL语句中单引号的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 大家好! 我不是很自豪地问这个,但这是我的问题: 字符串代码=" \\ \\''13 \''" 字符串代码必须包含以下信息: ''51'',''52' ',''63'',''other''... 从数据库中获取某些信息。当解析querry时,将查询这些 值: .... compCode in(@code) .... 有人能告诉我为什么在数据库中找不到这些值吗?我认为 out也许他自己引用了所以我尝试了以下内容: " 51" - >有效(但仅适用于一个值?) " \'''51''''' - 不工作 "'''51''" - 不工作 有没有人有一些想法,我怎么能找到正确的价值观? THX! DateTime startDate = new DateTime(2006,12,14,0,0,0); DateTime endDate = new DateTime(2006,12) ,15,23,59,59); string campaignCode =" O850"; string code =" \''13\''" ; //,\''51 \'' string language =" NL"; string startdate = Convert.ToString(startDate.Year +" - " + startDate.Month +" - " + startDate.Day); string enddate = Convert.ToString(endDate.Year +" - " + endDate.Month +" - " + endDate.Day); //定义连接 sqlConn = new SqlConnection(CONNECTION ); //定义查询 sqlQuery =" select count(*)as Aantal,sum(talktime)as TalkTime," ; +" sum(updatetime)为UpdateTime,sum(talktime + updatetime)为 HandleTime" +" from [ REPORTSERVERRPT] .dbo.SOMETHING" +"其中calldate @startdate和" +" calldate< @enddate和" +" compCode in(@code)和" +" sleutel in(" + select up.sleutel +" from [REPORTSERVER-RPT] .dbo.TEST as up +where up.CampaignName = @广告系列和 +up.lang = @language)" ;; 解决方案 SELECT * FROM表WHERE字段IN('''51'',''52'',''63'') SELECT * FROM表WHERE字段IN(''51'',''52'',''63'') Hi all! I am not very proud to ask this but here is my problem: string code = "\''13\''" The string code will have to contain following info:''51'',''52'',''63'',''other''...to get certain info from the database. When the querry is parsed thesevalues will be looked up:....compCode in (@code).... Can someone tell me why these values are not found in the DB? I figuredout that maybe he puts his own quotes so I tried the following: "51" -->works (but only for one value?)" \'' 51\'' " --does not work"''51''" --does not work Does anyone have some ideas how I can look up the right values? THX! DateTime startDate = new DateTime(2006,12,14,0,0,0);DateTime endDate = new DateTime(2006,12,15,23,59,59);string campaignCode = "O850";string code = "\''13\''"; //,\''51\''string language = "NL";string startdate = Convert.ToString(startDate.Year + "-" +startDate.Month + "-" + startDate.Day);string enddate = Convert.ToString(endDate.Year + "-" +endDate.Month + "-" + endDate.Day);// define connectionsqlConn = new SqlConnection(CONNECTION); // define query sqlQuery = "select count(*) as Aantal, sum(talktime) as TalkTime, "+ "sum(updatetime) as UpdateTime, sum(talktime + updatetime) asHandleTime "+ "from [REPORTSERVERRPT].dbo.SOMETHING"+ "where calldate @startdate and"+ " calldate < @enddate and "+ "compCode in (@code) and "+ "sleutel in ("+ "select up.sleutel "+ "from [REPORTSERVER-RPT].dbo.TEST as up "+ "where up.CampaignName = @campaign and "+ "up.lang = @language)"; 解决方案 SELECT * FROM Table WHERE Field IN (''51'',''52'',''63'') SELECT * FROM Table WHERE Field IN (''51'',''52'',''63'') 这篇关于SQL语句中单引号的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 09-27 04:17