要求,在每笔记录前添加一个字段,作为“序号”,实现这个要求,可以需要修改程序前台后台都行。
下面的方法,不想修改程序,直接修改存储过程即可。
参考下面代码片段:
代码
BEGIN
IF OBJECT_ID ( ' dbo.#Asstes_It_Computer_Search ' ) IS NOT NULL
DROP TABLE dbo.#Asstes_It_Computer_Search
CREATE TABLE dbo.#Asstes_It_Computer_Search
(
[ 序号 ] INT , -- 添加一个字段
[ 电脑 ] NVARCHAR ( 30 ),
[ 主用户 ] NVARCHAR ( 15 ),
[ 系统 ] NVARCHAR ( 50 ),
[ CPU ] NVARCHAR ( 20 ),
[ 内存 ] NVARCHAR ( 20 ),
[ 许可证 ] NVARCHAR ( 200 ),
[ 用途 ] NVARCHAR ( 30 ),
[ 备注 ] NVARCHAR ( 200 )
)
END
-- 添加ROW_NUMBER() OVER (ORDER BY [ComputerName])产生的值去填充"序号"字段。
INSERT INTO dbo.#Asstes_It_Computer_Search SELECT
ROW_NUMBER() OVER ( ORDER BY [ ComputerName ] ), [ ComputerName ] , [ WorkerName ] , [ Software ] , [ CPU ] , [ RAM ] , [ TrackLicence ] , [ Purpose ] , [ Remark ]
FROM [ dbo ] . [ udf_AssetsIt ] ()
IF OBJECT_ID ( ' dbo.#Asstes_It_Computer_Search ' ) IS NOT NULL
DROP TABLE dbo.#Asstes_It_Computer_Search
CREATE TABLE dbo.#Asstes_It_Computer_Search
(
[ 序号 ] INT , -- 添加一个字段
[ 电脑 ] NVARCHAR ( 30 ),
[ 主用户 ] NVARCHAR ( 15 ),
[ 系统 ] NVARCHAR ( 50 ),
[ CPU ] NVARCHAR ( 20 ),
[ 内存 ] NVARCHAR ( 20 ),
[ 许可证 ] NVARCHAR ( 200 ),
[ 用途 ] NVARCHAR ( 30 ),
[ 备注 ] NVARCHAR ( 200 )
)
END
-- 添加ROW_NUMBER() OVER (ORDER BY [ComputerName])产生的值去填充"序号"字段。
INSERT INTO dbo.#Asstes_It_Computer_Search SELECT
ROW_NUMBER() OVER ( ORDER BY [ ComputerName ] ), [ ComputerName ] , [ WorkerName ] , [ Software ] , [ CPU ] , [ RAM ] , [ TrackLicence ] , [ Purpose ] , [ Remark ]
FROM [ dbo ] . [ udf_AssetsIt ] ()