select *,cast(bin as decimal(10,2)) as bin2 into #tmp2 
from MyTable
where convert(varchar(10),[Time],120) between '2009-07-01' and '2009-10-28 23:59:59'
order by bin2 其中bin字段为varchar,不过其值能转换成2位浮点小数。1.如上一个SQL,我想在查询分析器运行的时候查看(打印、调试)#tmp2的数据,有没有办法?2.按照我后面一连串的勉强推测,貌似插入到#tmp2表的数据根本没有经过order by bin2排序,更不知有没有经过where的条件筛选,,,,,,,假若如我推测的话,有否解决办法?

解决方案 »

  1.   

    select * from #tmp2 ?
      

  2.   

    create table #tt
    (
      ID int identity(1,1) primary key,
      Bin varchar(10)
    )
    insert into #tt select 'aa'
    insert into #tt select 'bb'
    insert into #tt select 'cc'exec ('select * from #tt')
    ID          Bin
    ----------- ----------
    1           aa
    2           bb
    3           cc(3 行受影响)
      

  3.   

    1.
    select * from #tmp2 2.
    插入到#tmp2表的数据是where的条件筛选过的,也是排序过的。
      

  4.   

    1
    直接用
    SELECT * FROM #T
    2
    肯定有筛选,肯定有排序
      

  5.   

    补充
    1.#tmp2是一个临时表,而且我不止一个select语句,这个select语句还依赖之前的select语句的筛选结果#tmp的,我只是截取一部分出来。一有2个或以上的select语句,查询分析器的结果就不出现表格了,就出现多少行受影响就完了!
    这样的话,有没有办法查看#tmp2的数据?
      

  6.   

    --查询分析器中先按ctrl + tselect *,cast(bin as decimal(10,2)) as bin2 into #tmp2 
    from MyTable
    where convert(varchar(19),[Time],120) between '2009-07-01 00:00:00' and '2009-10-28 23:59:59'
    order by cast(bin as decimal(10,2)) select *,cast(bin as decimal(10,2)) as bin2 into #tmp2 
    from MyTable
    where convert(varchar(10),[Time],120) between '2009-07-01' and '2009-10-28'
    order by cast(bin as decimal(10,2)) select * from #tmp2 拷贝文本打印.
      

  7.   

    --上面最后一步是:
    select * from #tmp2 order by bin2
      

  8.   

    明白了,谢谢大家!不过还有点疑惑,为什么我上面的select语句都不显示数据出来,只显示影响行数,而在后面专门写select * from #tmp2就会把数据显示出来呢?
      

  9.   

    你的语句是插入语句,不是读出语句,所以要另外
    加一个select
      

  10.   

    你有
    insert into table
    select XXX
    或者
    select XXX
    into table from table
    的话,就是把select出来的东西插入到表里面,不是读出来
      

  11.   

    支持13楼,在排序的时候可以对排序列处理后再排序,如order by convert(char(6),getdate(),112)
      

  12.   

    select * from table where 1 = 1