【发布时间】:2016-10-12 20:54:10
【问题描述】:
ALTER PROCEDURE [dbo].[Testing]
@PageIndex INT = 1
,@PageSize INT = 10
,@type nvarchar(max)
,@city nvarchar(max)
,@query nvarchar(max)
,@RecordCount INT OUTPUT
AS
BEGIN
SET NOCOUNT ON;
DECLARE @mainQuery nvarchar(MAX),
@paramDeclaration nvarchar(500);
SET @paramDeclaration = ' @PageIndex INT = 1
,@PageSize INT = 10
,@type nvarchar(max)
,@city nvarchar(max)
,@RecordCount INT';
SET @mainQuery = '
;WITH DistinctMails AS
(
select Unit_Table.Unit_title, Vendor_Base_Price.Base_Price, Vendor_Base_Price.showprice, Category_Table.Title, Vendor_Registration.Business_Name,
Vendor_PrimaryInfo.Street_Address, Vendor_PrimaryInfo.Locality, Vendor_PrimaryInfo.Nearest_Landmark, Vendor_PrimaryInfo.City, Vendor_PrimaryInfo.State,
Vendor_PrimaryInfo.Country, Vendor_PrimaryInfo.PostalCode, Vendor_PrimaryInfo.Latitude, Vendor_PrimaryInfo.Longitude, Vendor_PrimaryInfo.ImageUrl,
Vendor_PrimaryInfo.ContactNo, Vendor_PrimaryInfo.Email,Vendor_PrimaryInfo.Vendor_ID,Vendor_Value_Table.Feature_ID,Vendor_Value_Table.Value_Text
,
ROW_NUMBER() OVER(PARTITION BY Vendor_PrimaryInfo.Vendor_ID ORDER BY Vendor_PrimaryInfo.Vendor_ID) AS RowNum
FROM Unit_Table INNER JOIN
Vendor_Base_Price ON Unit_Table.Unit_ID = Vendor_Base_Price.Unit_ID INNER JOIN
Vendor_PrimaryInfo ON Vendor_Base_Price.Vendor_ID = Vendor_PrimaryInfo.Vendor_ID INNER JOIN
Vendor_Registration ON Vendor_Base_Price.Vendor_ID = Vendor_Registration.Vendor_ID AND
Vendor_PrimaryInfo.Vendor_ID = Vendor_Registration.Vendor_ID INNER JOIN
Category_Table ON Vendor_Registration.Category_ID = Category_Table.Category_ID
LEFT JOIN
Vendor_Value_Table ON Vendor_Registration.Vendor_ID = Vendor_Value_Table.Vendor_ID LEFT JOIN
Feature_Table ON Vendor_Value_Table.Feature_ID = Feature_Table.Feature_ID
where Vendor_Registration.Category_ID=@type and Vendor_PrimaryInfo.City=@city'
SET @mainQuery = @mainQuery + @query +'
)
SELECT * into #Results
FROM DistinctMails
WHERE RowNum = 1
SELECT @RecordCount = COUNT(*)
FROM #Results
SELECT * FROM #Results
WHERE RowNum BETWEEN(@PageIndex -1) * @PageSize + 1 AND(((@PageIndex -1) * @PageSize + 1) + @PageSize) - 1
DROP TABLE #Results'
exec sp_executesql @mainQuery, @paramDeclaration, @PageIndex = @PageIndex, @PageSize = @PageSize, @type = @type,
@city = @city, @RecordCount = @RecordCount
END
**不能将 RecordCount 作为输出 ** 请给我一些意见我被困在这里 提前致谢
如您所见,我有一个名为@query 的变量,我只想在其中附加查询,其中包含各种and and or 运算符,我该怎么做?
提前致谢
【问题讨论】:
标签: asp.net stored-procedures sql-server-2012