SELECT IP_PoolV4.ID,IP_PoolV4.IP,IP_PoolV4.Used,IP_PoolV4.Area,IP_PoolV4._UserName,IP_PoolV4.Note,IP_PoolName.ID AS PoolID,IP_PoolName.Name AS PoolName,IP_PoolName.Gateway,IP_PoolName.Mask,IP_PoolName.Type,IP_PoolName.HostID,IP_Host.Name AS HostName FROM IP_PoolV4 INNER JOIN IP_PoolName ON IP_PoolV4.PoolID = IP_PoolName.ID INNER JOIN IP_Host ON IP_PoolName.HostID = IP_Host.ID
WITH TT AS ( @sql ) (伪代码,@sql代表上面的SQL语句)
SELECT * FROM (SELECT *,Row_Number() OVER (ORDER BY ID) AS RowNo FROM TT ) AS T2 WHERE RowNo BETWEEN 1 AND 50;
Select Count(*) As TC FROM TT;
代码没有问题,但是TT表只在紧跟后的一条语句有效,第二句就不行了,我看网上有专家说,WITH AS 语句后如果全是SELECT语句,那么这临时表就是有效的,直到遇到其它语句。