我有通过text1 text2 输入两个编号(字符型)如:Y12345,Y12346
想通过这些编号得到他们的值  如Y12345的值为12345 , Y12346的值为12346
我的语句这样写的
update pand1 set beizhu= '* 'from pand1 where 编号 between VAL( " & Trim(Text2.Text) & ") and val (" & Trim(Text3.Text) & ")
但报错为:VAL是不可识别的函数,请问我该怎么写这条SQL语句

解决方案 »

  1.   

    update pand1 set beizhu= '* 'from pand1 where 编号 between ( " & Trim(val(Text2.Text)) & ") and  (" & Trim(val(Text3.Text)) & ") 
      

  2.   

    不管你VB里怎么去拼接SQL语句,反正你要得到如下语句就可以了:update pand1
    set beizhu = '*'
    from pand1
    where 编号 between replace(你的变量值,'Y','') ......
      

  3.   

    其实这个处理在应用程序里处理就好了,有那么多处理函数,可以用mid()函数(如果我没弄错你用的是VB语言或者VBSCRIPT)
      

  4.   

     between ( " & Trim(val(Text2.Text)) & ") and  (" & Trim(val(Text3.Text)) & ") 这样写有问题,系统报错为:“字符型转换成数值型出现语法错误”
    我的系统是VB做的!
      

  5.   

    楼主朋友,就这个问题来看,主要是val,和trim都不是SQL的函数,必须选择别的函数或换一种判断方法.比较好的应该是用replace函数,将字段值中的'Y'给替换掉,方法如下update pand1
      set beizhu= '* '
    from pand1 
    where 编号 between cast(replace(text1.text,'Y','') as int) and cast(replace(text2.text,'Y','') as int)友情提示:这里没有判断到底text1.text表示的数值与text2.text表示数值的大小,应该在前台程序中加以判断,保证送入SQL执行的数据满足正常要求.
      

  6.   

    楼主你是要在哪里写SQL语句呀,是在VB中写通过ADO传入SQL,还是直接在SQL中写?
    在VB中的写法为:dim strSQL as string
    strSQL=""
    strSQL=strSQL + "update pand1" + vbCR 
    strSQL=strSQL + "  set beizhu= '* ' " + vbCR 
    strSQL=strSQL + "from pand1 " + vbCR 
    strSQL=strSQL + "where 编号 between cast(replace(" & text1.text & ",'Y','') as int) and cast(replace(" & text2.text & ",'Y','') as int)" 
    楼主你把这个变量strSQL送给ADO就可以达到你要的效果了,但是一定要检查text1.text表示的数值与text2.text表示数值的大小,以免出现异常中断程序.
      

  7.   

    还是有问题 我输入进去的值后,系统报错:我的输入的值对应的列无效  我晕倒
    我现在是这样做的
    我现在用VB这样做
    Dim n As Integer
    Dim m As Integer
    'Adodc1.CommandType = adCmdText
    'Adodc1.RecordSource = "select * from pand1 where pandiandanhao = '" & Trim(Text2.Text) & "'"
    'Adodc1.Refresh
    'n = Val(Adodc1.Recordset.Fields("id"))'Adodc1.CommandType = adCmdText
    'Adodc1.RecordSource = "select * from pand1 where pandiandanhao = '" & Trim(Text3.Text) & "'"
    'Adodc1.Refresh
    'm = Val(Adodc1.Recordset.Fields("id"))
    Adodc1.CommandType = adCmdText
    Adodc1.RecordSource = "select * from pand1 where   pandiandanhao  between cast(replace(  " & Trim(Text2.Text) & " ,'Y','') as int) and cast(replace(" & Trim(Text3.Text) & " ,'Y','') as int)  and beizhu = ' T '"
    Adodc1.Refresh
    但还有问题,不知道该怎么处理,希望大家帮忙看还有没有别的方法

    pandiandanhao 就是我说的编号,id是另外一列,只数据库自动编号的,为int型,但还是有问题