如何实现视图中添加标识列?
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
ALTER VIEW dbo.PS_TaskOldView
AS
SELECT TOP 100 PERCENT c.PS_TaskOID AS PS_TaskOldViewOID, c.ProjectName,
c.ProjectType, c.ProjectKind, c.BeginMoney, c.SignForDate, c.AssessKind,
c.FlowChineseName, b.resolutionCode, b.USR_LOGIN, b.PersonName,
b.UCML_UserOID, c.PSAGZOID, c.ProjectID, c.RepID, c.InstanceID,
a.ActivityChineseName, d.Memo AS Memo, d.WhyReturn AS WhyReturn,
d.BeConsUnit AS BeConsUnit, d.AssessStatu AS AssessStatu
FROM dbo.TaskTicket a INNER JOIN
dbo.AssignTask b ON a.TaskTicketOID = b.TaskTicketOID INNER JOIN
dbo.PS_Task c ON a.InstanceID = c.InstanceID INNER JOIN
dbo.PS_AssessTask d ON c.PSAGZOID = d.PS_AssessTaskOID
ORDER BY c.SignForDate DESC
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
我想在视图PS_TaskOldView中增加一int型的列用来显示视图的记录编号。虽然可以用临时表,但是临时表有时间限制,貌似过一段时间就自动没了。。我是要直接在视图里面加一个字段。请教,该如何做。
[解决办法]
视图是执行的时候才编译的,就算加row_number,每次执行的id会根据基础表的变动而变动,所以你这个想法不行
[解决办法]
Select *,Row_Number() OVER(ORder by SignForDate DESC) as rownumber
From PS_TaskOldView
[解决办法]
视图在添加上序号也是重新按照orderby 来的。没办法标识数据的。
lz可以使用固定到表中,来实现标识。比如自增列
[解决办法]