"select UsedTime From ActiveRecord where ([UsedTime] between D1 AND D2) 这样写不对吗?为什么总是说"D1"和"D2"是无效的列名~~~~D1和D2是datetime型的变量~~菜鸟求指教~~~

解决方案 »

  1.   

    declare D1 datetime
    declare D2 datetime
    set D1 = '2000-1-1'
    set D2 = '2001-1-1'select UsedTime From ActiveRecord where ([UsedTime] between D1 AND D2)
    String sql = "select UsedTime From ActiveRecord where ([UsedTime] between " +D1+" AND "+D2+")"
      

  2.   

    "select UsedTime From ActiveRecord where ([UsedTime] between '"+D1+ "' AND '"+D2+"'") 
      

  3.   

     
    declare @D1 datetime,@D2 datetime
    set @D1='2011-02-23'
    set @D2='2011-02-25'
    select 1 where getdate() between  @D1 and @D2/*
    -----------
    1
      

  4.   

    --列UsedTime,D1,D2都是ActiveRecord表里的
    select UsedTime from ActiveRecord where UsedTime between D1 and D2如果上面的还不行看看下面这个
    declare D1 datetime
    declare D2 datetime
    set D1 = '2010-1-1'
    set D2 = '2011-1-1'
    select UsedTime from ActiveRecord where UsedTime between D1 and D2
      

  5.   

    呃~~明白了~变量不能写在string里......我的代码里这句话后面还有,现在是
    "select ServiceCode, ManuType, NetDiskSize, UsedTime From ActiveRecord where ([UsedTime] between 2010/1/1 0:00:00 AND 2011/12/31 0:00:00) AND [NetDiskSize]='5'"运行后说  '0' 附近有语法错误。  求教这个又是为什么....
      

  6.   

    "select ServiceCode, ManuType, NetDiskSize, UsedTime From ActiveRecord where ([UsedTime] between '2010-1-1 0:00:00' AND '2011-12-31 0:00:00') AND [NetDiskSize]='5'"
      

  7.   


    如果你的[NetDiskSize]是数值型,就不用''了"select ServiceCode, ManuType, NetDiskSize, UsedTime From ActiveRecord where ([UsedTime] between '2010-1-1 0:00:00' AND '2011-12-31 0:00:00') AND [NetDiskSize]=5"