[英]How to create stored procedure to get value of previous column Entry in SQL Server 2008?
数据库表: UserTime
UserTimeId int(pk)
LoginStatus nvarchar
LoginStatus
仅存储两条信息: In
和Out
例如:
UserTimeId LoginStatus
--------------------------
1 In
2 Out
3 In
4 Out
我想创建一个存储过程来检查上一列的LoginStatus
的值是什么。
在C#代码中,我要这样实现:
if (StoredProcedureCheckLoginStatus='In')
{
dothis...
}
else
{
do this....
}
使用CTE。 附样品:
WITH CTE as (
SELECT
RN = ROW_NUMBER() OVER (ORDER BY EmployeeID),
*
FROM HumanResources.Employee
)
SELECT
[Previous Row].*,
[Current Row].*,
[Next Row].*
FROM CTE [Current Row]
LEFT JOIN CTE [Previous Row] ON
[Previous Row].RN = [Current Row].RN - 1
LEFT JOIN CTE [Next Row] ON
[Next Row].RN = [Current Row].RN + 1
WHERE
[Current Row].EmployeeID = 5
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.