以下是我在申请中写的程序。但我想在列表中找到LogSource列,但我无法从此存储过程中获取它。
CREATE PROCEDURE [dbo].[GetApplicationLogs]
-- Add the parameters for the stored procedure here
@Skip int,
@Pagesize int
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
-- Insert statements for procedure here
WITH TableDatawithRowNumber AS
( SELECT dbo.ApplicationLog.* ,ROW_NUMBER() OVER (ORDER BY LoggedDate DESC) AS RowNumber,
(SELECT COUNT(*) AS Expr1
FROM ApplicationLog ) AS TotalRecords
from ApplicationLog
)
SELECT * FROM TableDatawithRowNumber
WHERE RowNumber > @Skip AND RowNumber <= (@Pagesize+@Skip)
END
此表不包含LogSource列,但它中包含LogSourceID,它是此表中的外键和LogSource表中的主键。我想在我的列表中显示,但我无法在视图中看到它。我只能使用LogSourceId而不能使用LogSource。所以请帮助我。
答案 0 :(得分:0)
我认为你只需要在LogSource表上进行左连接
WITH TableDatawithRowNumber AS
( SELECT dbo.ApplicationLog.* ,ROW_NUMBER() OVER (ORDER BY LoggedDate DESC) AS RowNumber, logSource.LogSource
(SELECT COUNT(*) AS Expr1
FROM ApplicationLog ) AS TotalRecords
from ApplicationLog as appLog
left join LogSource as logSource on appLog.LogSourceId = logSource.LogSourceId
)