技术交流 >>  Visual Basic >> SQL语句中如何使用单引号   ( 加入天天收藏夹)
     

用户:bowing
积分:0
发贴数量:7
注册日期:2004-9-13
  消息   查看   好友   回复 时间:2004-9-14 21:06:46


SQL语句中如何使用单引号
I got an error with following sql statement:
    "update Group set name = 'q's' where ID =2",
    it seems i can't use " ' " within value update command, right??
    wish get your great help!






  免费网络赚钱教程,一步一步教你轻轻松松赚钱!
  本网站最新开发的天天收藏夹(www.ttscj.com),定制你的主页!

用户:shark20
积分:0
发贴数量:4
注册日期:2004-9-13
  消息   查看   好友   回复 时间:2004-9-14 21:07:30
在Sql语句中,如果包括单引号(“ '”)那么必须将其转化成两个单引号(“''”),否则就 会出错。所以这条语句应该这样:
     "update group set name='q''s' where id=2"


  免费网络赚钱教程,一步一步教你轻轻松松赚钱!
  本网站最新开发的天天收藏夹(www.ttscj.com),定制你的主页!

用户:【木瓜】
积分:330
发贴数量:55
注册日期:2004-11-6
  消息   查看   好友   回复 时间:2004-11-6 9:11:06
[该贴于 2004-11-10 9:10:23 第 1 次修改]

可以采用第三方方案。

1、将单引号转化成全角单引号,然后update这个转化后的字符

update Group set name = replace("'q's'","'","’") where ID =2

2、读取时,再转化回来

Select name From Group Where Id=2

sStr=Replace(RS("name"),"’","'")

欢迎访问 www.Emugua.net

  免费网络赚钱教程,一步一步教你轻轻松松赚钱!
  本网站最新开发的天天收藏夹(www.ttscj.com),定制你的主页!

用户:mmxx
积分:0
发贴数量:3
注册日期:2005-1-12
  消息   查看   好友   回复 时间:2005-1-12 17:49:21
给你看一个莽的:
StrSQL = StrSQL & " left join (select count(order_id) as opens" & Trim(str(Counter)) & ",sum(order_k) as opentotal" & Trim(str(Counter)) _
                        & ", " & StrDate & " as saledate" & Trim(str(Counter)) & "1 from " & StrTable & " where (order_type='开户' or order_type='购气') and usetype='" & RsUsetype("usetype") & "' " _
                        & " group by " & StrDate & ") a" & Trim(str(Counter)) & "1 on x.saledate=a" & Trim(str(Counter)) & "1.saledate" & Trim(str(Counter)) & "1) " _
                        & " left join (select count(order_id) as sales" & Trim(str(Counter)) & ",sum(order_k) as saletotal" & Trim(str(Counter)) _
                        & ", " & StrDate & " as saledate" & Trim(str(Counter)) & "2 from " & StrTable & " where (order_type='退气' and order_Amount < 0) and usetype='" & RsUsetype("usetype") & "' " _
                        & " group by " & StrDate & ") a" & Trim(str(Counter)) & "2 on x.saledate=a" & Trim(str(Counter)) & "2.saledate" & Trim(str(Counter)) & "2) " _
                        & " left join (select count(order_id) as replaces" & Trim(str(Counter)) _
                        & ", " & StrDate & " as saledate" & Trim(str(Counter)) & "3 from " & StrTable & " where order_type='换表' and usetype='" & RsUsetype("usetype") & "' " _
                        & " group by " & StrDate & ") a" & Trim(str(Counter)) & "3 on x.saledate=a" & Trim(str(Counter)) & "3.saledate" & Trim(str(Counter)) & "3) " _
                        & " left join (select count(order_id) as cardlosts" & Trim(str(Counter)) _
                        & ", " & StrDate & " as saledate" & Trim(str(Counter)) & "4 from " & StrTable & " where order_type='补卡' and usetype='" & RsUsetype("usetype") & "' " _
                        & " group by " & StrDate & ") a" & Trim(str(Counter)) & "4 on x.saledate=a" & Trim(str(Counter)) & "4.saledate" & Trim(str(Counter)) & "4) " _
                        & " left join (select '" & RsUsetype("usetype") & "' as usetype" & Trim(str(Counter)) & ",sum(order_k) as total" & Trim(str(Counter)) & ",sum(order_money) as totalmoney" & Trim(str(Counter)) & "" _
                        & ", " & StrDate & " as saledate" & Trim(str(Counter)) & "5 from " & StrTable & " where (order_type='开户' or order_type='购气' or order_type='退气'  and order_Amount < 0) and usetype='" & RsUsetype("usetype") & "' " _
                        & " group by " & StrDate & ") a" & Trim(str(Counter)) & "5 on x.saledate=a" & Trim(str(Counter)) & "5.saledate" & Trim(str(Counter)) & "5) "

  免费网络赚钱教程,一步一步教你轻轻松松赚钱!
  本网站最新开发的天天收藏夹(www.ttscj.com),定制你的主页!