源表A:
a               b             c
2008           10             4
2008            4            24我想得到的表B:
a              b              c               d
2008          10              4              2008-10-4
2008           4             24              2008-4-24
其中:a、 b、 c为整数列,我希望查询出来的d 为日期列 我写了这样的一个查询:
select  a,b,c,concat(a,"-",b,"-",c) as d form[表A]
结果不能执行。请教这条查询如何写?

解决方案 »

  1.   

    补充一下:
    A表将年、月、日分开存放,可我希望按日期来设置查询。完整的查询语句我是这样写的:
    select  a,b,c,concat(a,"-",b,"-",c) as d form[表A] where d between '1/10/2008' and '5/10/2008'结果也是不能执行。再次请教!
      

  2.   

    select cast(a as varchar(4))+'-'+cast(b as varchar(2))+'-'+cast(c as varchar(2)) from a
      

  3.   

    create table A(a varchar(4),b varchar(2),c varchar(2))
    go
    insert into A select '2008','10','4'
    union all select '2008','4','24'
    go
    --select * from A
    --go
    select a,b,c,cast(a+'-'+b+'-'+c as datetime) as d from A where cast(a+'-'+b+'-'+c as datetime) > '2008-10-01'drop table A
    /*
    a    b    c    d                                                      
    ---- ---- ---- ------------------------------------------------------ 
    2008 10   4    2008-10-04 00:00:00.000(所影响的行数为 1 行)
    */
      

  4.   

    这是一个实际的查询语句:select pzrqn,pzrqy,pzrqr,cast(pzrqn+'-'+pzrqy+'-'+pzrqr as datetime) as pzrq from [z_tablqpz] where cast(pzrqn+'-'+pzrqy+'-'+pzrqr as datetime) > '2008-10-01'执行这条语句出错。这条语句与上面不同之处是:
    pzrqn  就是  a
    pzrqy  就是  b
    pzrqr  就是  c
    [z_tablqpz]  就是 表A
    a b c 三列都是 INT 型的,我只能查询,不是新建的。我想,是不是数据类型不对,导致查询不完成?
      

  5.   

    我只是想将年、月、日这三列整到一起,再按日期来查询。比如这样:  where d between '2008-10-01' and '2008-10-09'所以,我非得将它们整到一起来比较,如果年、月、日 分开,那条件太复杂了。为解决这个问题,还有什么好的方法吗?