您的位置:程序门 -> ms-sql server -> 基础类



请问一个关于select语句列拼装的问题,在线等~~~~~~~


[收藏此页] [打印本页]选择字色:背景色:字体:[][][]


请问一个关于select语句列拼装的问题,在线等~~~~~~~[已结贴,结贴人:zdrone]
发表于:2007-04-27 16:01:33 楼主
请问我如何
select   *   from   table1
select   *   from   table2
选出的内容全部按照列显示。
比如

table1:
t1fields1   t1fields2   t1fields3
***               ***               ***
***               ***               ***
***               ***               ***
table2:
t2fields1   t2fields2   t2fields3
***               ***               ***
***               ***               ***
***               ***               ***

选择后的记录集应该是
t1fields1   t1fields2   t1fields3   t2fields1   t2fields2   t2fields3
***               ***               ***               ***               ***               ***
***               ***               ***               ***               ***               ***
***               ***               ***               ***               ***               ***

如果有n多个select   从多个表种选出了n多个字段,我将这些字段都按照上面的
形式按列组合起来,如果是行的话我知道是用union   all   但是列就是不知道。
麻烦各位了


发表于:2007-04-27 16:08:501楼 得分:20
select   table1.*,table2.*   from   table1,table2   where   table1.id=table2.id
发表于:2007-04-27 16:22:092楼 得分:0
没有楼上的那么简单
因为实际操作的时候
一条select   语句需要关联很多个表
比如说
    select   b.data2/1000  
    from   profit   a   left   join   profit_item   b   on   a.id=b.profit  
    where   a.enterprise=@enterprise   and   a.report_y=@dty   and   a.report_m=@dtm   and   a.audit> 0   and   b.pid=1
----这选出了第一个字段----
    select   b.data2/1000  
    from   profit   a   left   join   profit_item   b   on   a.id=b.profit  
    where   a.enterprise=@enterprise   and   a.report_y=@dty   and   a.report_m=@dtm   and   a.audit> 0   and   b.pid=2
----这选出了第二个字段----
.
.
.
.
.
.
.
以上select   算是比较简单的了。有很多复杂的select,我想把每个select   选出的值拼装成
(每个select只选择一行记录),然后再用union   all   拼装成一个多行记录集的表


快速检索

最新资讯
热门点击