此查询引发错误:
DECLARE @CategoryId int
SELECT @CategoryId = 1
exec [USP_GetLimitedRecords]
@Query = N'SELECT b.* FROM Boxes b INNER JOIN Categories c ON b.CategoryId = c.Id WHERE c.Id= ' + @CategoryId,
@PrimaryKey = N'id',
@PageNo = 1,
@PageSize = 20
错误是:
Msg 102,Level 15,State 1,Line 2'+'附近的语法不正确。
此查询有效
exec [USP_GetLimitedRecords]
@Query = N'SELECT b.* FROM Boxes b INNER JOIN Categories c ON b.CategoryId = c.Id WHERE c.Id= 1',
@PrimaryKey = N'id',
@PageNo = 1,
@PageSize = 20
答案 0 :(得分:3)
请您尝试使用以下查询,谢谢
DECLARE @CategoryId int
DECLARE @MyQuery NVARCHAR(250)
SELECT @CategoryId = 1
SET @MyQuery = N'SELECT b.* FROM Boxes b INNER JOIN Categories c ON b.CategoryId = c.Id WHERE c.Id= ' + CAST( @CategoryId AS VARCHAR)
exec [USP_GetLimitedRecords]
@Query = @MyQuery,
@PrimaryKey = N'id',
@PageNo = 1,
@PageSize = 20