I need to know if the used INTO
SQL Server and equivalent ROWNUM
in SQL Server
我需要知道在SQL Server中使用的INTO SQL Server和等效的ROWNUM
SELECT
SERIE, CORRELATIVO
INTO
vSerie, vCorrelativo
FROM
SIG.SAF_SERIES_DOCUMENTOS_DET
WHERE
COMPANIA = pCompania
AND MONTO = pMonto
AND ESTADO = 'P'
AND ROWNUM = 1;
1 个解决方案
#1
1
This should do it, although you're missing an order by:
这应该这样做,虽然你错过了一个订单:
SELECT top 1
@vSerit = SERIE,
@vCorrelativo = CORRELATIVO
FROM SIG.SAF_SERIES_DOCUMENTOS_DET
WHERE COMPANIA = @pCompania
AND MONTO = @pMonto
AND ESTADO = 'P'
If you need something else than the first row, You can also do a row_number() window function as a column into your select and use that to limit the data or use offset / fetch if you're in SQL Server 2012 or use top twice with asc / desc order by
如果你需要的不是第一行,你也可以将row_number()窗口函数作为一个列进入你的select并使用它来限制数据或使用offset / fetch如果你在SQL Server 2012中或使用top两次用asc / desc命令
#1
1
This should do it, although you're missing an order by:
这应该这样做,虽然你错过了一个订单:
SELECT top 1
@vSerit = SERIE,
@vCorrelativo = CORRELATIVO
FROM SIG.SAF_SERIES_DOCUMENTOS_DET
WHERE COMPANIA = @pCompania
AND MONTO = @pMonto
AND ESTADO = 'P'
If you need something else than the first row, You can also do a row_number() window function as a column into your select and use that to limit the data or use offset / fetch if you're in SQL Server 2012 or use top twice with asc / desc order by
如果你需要的不是第一行,你也可以将row_number()窗口函数作为一个列进入你的select并使用它来限制数据或使用offset / fetch如果你在SQL Server 2012中或使用top两次用asc / desc命令