set @l_SQL = 'SELECT TOP '+CONVERT(VARCHAR(10),@NUM)+' 1 AS C, * FROM B '
set @l_SQL = @l_SQL + 'UNION '
set @l_SQL = @l_SQL + 'SELECT 0 AS C,* FROM B WHERE B02 NOT IN'
SET @l_SQL = @l_SQL + '(SELECT TOP '+CONVERT(VARCHAR(10),@NUM)+' B02 FROM B) '
真奇怪,那些为1的怎么会在最后的。
那是改成这样就可了。但这是为什么呀
select '0' as c,* from tdzxd where tybh='M00067-0BU' and xhid not in
(select top 3 xhid from tdzxd where tybh='M00067-0BU')
union select top 3 '1' as c,* from tdzxd where tybh='M00067-0BU'