以下是我在应用程序中写的过程。但是我想要列表中的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。所以请帮助我。
我认为您只需要在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
)