select WsgmGoods, wsgmwo 
       from sdwsgm
       where   WsgmGoods not like 'B01%' and WsgmGoods not like 'B02%' and WsgmGoods not like 'B13%' and WsgmGoods not like 'B06%'and WsgmGoods not like 'B04%'unionselect top 1 WsgmGoods, wsgmwo 
       from sdwsgm
       where  WsgmGoods  like 'B01%'unionselect top 1 WsgmGoods , wsgmwo 
       from sdwsgm
       where   WsgmGoods  like 'B02%'unionselect top 1 WsgmGoods, wsgmwo 
       from sdwsgm 
       where   WsgmGoods  like 'B13%'unionselect top 1 WsgmGoods, wsgmwo 
       from sdwsgm
       where   WsgmGoods  like 'B04%'
union
select top 1 WsgmGoods, wsgmwo        from sdwsgm
       where   WsgmGoods  like 'B06%'我想问问,为什么我的这语句做成视图后,就只能查询出第一个select语句的结果,其他的就 不能查询出来.如果在查询分析器里就可以.如果把top 1 语句都去掉,那就可以正常查询出来,但是我需要的就第一条select语句的全部结果,其他select语句的第一条查询结果,并且组成视图!希望那位大虾帮帮忙!

解决方案 »

  1.   

    select WsgmGoods, wsgmwo 
           from sdwsgm
           where   WsgmGoods not like 'B01%' and WsgmGoods not like 'B02%' and WsgmGoods not like 'B13%' and WsgmGoods not like 'B06%'and WsgmGoods not like 'B04%'union allselect top 1 WsgmGoods, wsgmwo 
           from sdwsgm
           where  WsgmGoods  like 'B01%'union allselect top 1 WsgmGoods , wsgmwo 
           from sdwsgm
           where   WsgmGoods  like 'B02%'union allselect top 1 WsgmGoods, wsgmwo 
           from sdwsgm 
           where   WsgmGoods  like 'B13%'union allselect top 1 WsgmGoods, wsgmwo 
           from sdwsgm
           where   WsgmGoods  like 'B04%'
    union all
    select top 1 WsgmGoods, wsgmwo        from sdwsgm
           where   WsgmGoods  like 'B06%'--这样试试呢?
      

  2.   

    Try:union
    --
    union all
    SP??
      

  3.   

    会不会有重复数据被union 给合并了?你把所有的select语句分开执行看看有没有什么结果
      

  4.   

    不行呀union all,还有不会有数据重复的
    请大家再帮帮忙拉!
      

  5.   

    从条件看不会重复的打了sp几?至少升级到sp3
      

  6.   

    会吗?
    lz是不是在如果数据不重复的话,lz的UNION是不回有错的啊看看你的VIEW的代码