在不使用 Row_Number() 函数的情况下将行号添加到 SQL Server 中的 SELECT 查询结果 [英] Adding Row Numbers To a SELECT Query Result in SQL Server Without use Row_Number() function

查看:32
本文介绍了在不使用 Row_Number() 函数的情况下将行号添加到 SQL Server 中的 SELECT 查询结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在不使用 Row_Number() 函数的情况下向 SELECT 查询添加行号.
并且不使用用户定义的函数或存储过程.

i need Add Row Numbers To a SELECT Query without using Row_Number() function.
and without using user defined functions or stored procedures.

Select (obtain the row number) as [Row], field1, field2, fieldn from aTable

更新

我正在使用 SAP B1 DIAPI 进行查询,该系统不允许在 select 语句中使用 rownumber() 函数.

i am using SAP B1 DIAPI, to make a query , this system does not allow the use of rownumber() function in the select statement.

再见.

推荐答案

我不确定这是否适用于您的特定情况,但是您可以使用存储过程执行此查询吗?如果是这样,您可以:

I'm not sure if this will work for your particular situation or not, but can you execute this query with a stored procedure? If so, you can:

A) 创建一个包含所有正常结果列的临时表,以及一个作为自动递增标识的 Row 列.

A) Create a temp table with all your normal result columns, plus a Row column as an auto-incremented identity.

B) 选择-插入您的原始查询,无行列(SQL 会自动为您填写)

B) Select-Insert your original query, sans the row column (SQL will fill this in automatically for you)

C) 在结果集的临时表上选择 *.

C) Select * on the temp table for your result set.

不是最优雅的解决方案,但会完成您想要的行编号.

Not the most elegant solution, but will accomplish the row numbering you are wanting.

这篇关于在不使用 Row_Number() 函数的情况下将行号添加到 SQL Server 中的 SELECT 查询结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆