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语句的第一条查询结果,并且组成视图!希望那位大虾帮帮忙!
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语句的第一条查询结果,并且组成视图!希望那位大虾帮帮忙!
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%'--这样试试呢?
--
union all
SP??
请大家再帮帮忙拉!
lz是不是在如果数据不重复的话,lz的UNION是不回有错的啊看看你的VIEW的代码