select * from lssj where rfkh=0015581409 
能查询到如下结果: 
id  kk       jh   je     ye        sj 
52 0015581409 0 8.0000 8.0000 2009-01-06 09:55:19.000 
52 0015581409 0 -8.0000 .0000 2009-01-06 10:11:13.000 
52 0015581409 0 8.0000 8.0000 2009-01-06 10:19:05.000 
52 0015581409 0 8.0000 8.0000 2009-01-15 09:50:09.000 
52 0015581409 5 8.0000 .0000 2009-01-15 11:29:26.117 
52 0015581409 0 8.0000 8.0000 2009-01-16 09:39:37.000 
52 0015581409 0 8.0000 8.0000 2009-05-09 09:48:26.000 
请问要如何写查询
可以找到2009-5-6之前的数据;
        2009-5-6到2009-5-10之间的数据
如何插入条数据
数据类型
id int
kh nchar
jh tinyint
je money
ye money
sj datetime
fs varchar
zl varchar
sky nchar

解决方案 »

  1.   

    --找到2009-5-6之前的数据
    select * from lssj where rfkh=0015581409 and datediff(day,sj,'2009-5-6')>0--2009-5-6到2009-5-10之间的数据select * from lssj where rfkh=0015581409 and sj>'2009-05-06' and sj<'2009-05-10' --不包含5月10日的数据,如要包含用05-11
      

  2.   

    where datediff(dd,sj,2009-5-6)>0where sj between '2009-5-6' and '2009-5-11' 
      

  3.   

    请问要如何写查询 
    可以找到2009-5-6之前的数据; 
    select * from  lssj where kh=0015581409 and sj<'2009-5-6'
            2009-5-6到2009-5-10之间的数据 
    select * from  lssj where kh=0015581409 and sj>='2009-5-6' and sj<'2009-5-10'
      

  4.   

    --可以找到2009-5-6之前的数据; 
    select * from  lssj where kh=0015581409 and datediff(dd,'2009-5-6',sj)<0
    --2009-5-6到2009-5-10之间的数据
    select * from  lssj where kh=0015581409 and sj>='2009-5-6' and sj<'2009-5-10'
      

  5.   

    2009-5-6之前的数据:select * from lssj where rfkh=0015581409 and sj<'2009-5-6'
      

  6.   

    select * from lssj where rfkh=0015581409 and sj>'2009-05-06' and sj<'2009-05-10 23:59:00' 
      

  7.   

     用 datediff(dd,'2009-5-6',sj)<0 效率比较高 邹老大说的
      

  8.   

    如何插入条数据 
    数据类型 
    id int 
    kh nchar 
    jh tinyint 
    je money 
    ye money 
    sj datetime 
    fs varchar 
    zl varchar 
    sky nchar??????
      

  9.   

    2009-5-6到2009-5-10之间的数据:select * from  lssj where kh=0015581409 and sj>='2009-5-6' and sj<'2009-5-10'
      

  10.   

    如何插入条数据 :
    declare @t table(id int ,kh nchar, jh tinyint, je money 
    ,ye money ,sj datetime, fs varchar ,zl varchar ,sky nchar)insert @t
    select 1,'a',10,32.50,5000,'2009-06-12','0','a','@'select * from @tid          kh   jh   je                    ye                    sj                      fs   zl   sky
    ----------- ---- ---- --------------------- --------------------- ----------------------- ---- ---- ----
    1           a    10   32.50                 5000.00               2009-06-12 00:00:00.000 0    a    @(1 行受影响)
      

  11.   

    2009-5-6之前的数据; SQL codeselect * from  lssj where kh=0015581409 and sj<'2009-5-6'
    2009-5-6到2009-5-10之间的数据 SQL codeselect * from  lssj where kh=0015581409 and sj>='2009-5-6' and sj<'2009-5-10'
      

  12.   

    --添加字段
    alter table lssj add fs varchar 
    alter table lssj  add zl varchar 
    alter table lssj  add sky nchar
    --添加数据
    insert lssj 
    select   。。 union all
    select 
      

  13.   

    create table lssj (id int ,kh nchar, jh tinyint, je money 
        ,ye money ,sj datetime)
     insert lssj
    values( 1,'a',10,32.50,5000,'2009-06-12')
    alter table lssj add fs varchar 
    alter table lssj  add zl varchar 
    alter table lssj  add sky nchar
    update  lssj
    set fs='a',zl ='e', sky=N'阿 '
    where id=1
    select * from lssj
    /*------------
     1 a 10 32.50 5000.00 2009-06-12 00:00:00.000 a e 阿
    ------------*/
      

  14.   

    create table lssj (id int ,kh nchar, jh tinyint, je money 
        ,ye money ,sj datetime)
    alter table lssj add fs varchar 
    alter table lssj  add zl varchar 
    alter table lssj  add sky nchar
    --先添加字段后直接插入
     insert lssj
    values( 1,'a',10,32.50,5000,'2009-06-12','a','e',N'阿')