詳細を説明します。私はSPを書いてそれをうまく実行しました。SQL Server 2008ストアドプロシージャの実行の問題
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER PROCEDURE [dbo].[InvoiceReference]
@StartDate DateTime = NULL,
@EndDate DateTime = NULL,
@DocumentType nvarchar(50) = NULL,
@Partners nvarchar(MAX) = NULL,
@PriceFrom numeric(19,6) = NULL,
@PriceTo numeric(19,6) = NULL,
@VATFrom numeric(19,6) = NULL,
@VATTo numeric(19,6) = NULL,
@PageNumber INT,
@PageSize INT
AS
BEGIN SET NOCOUNT ON;
DECLARE @StartPage as int
DECLARE @EndPage as int
SET @StartPage = ((@PageNumber-1) * @PageSize) + 1;
SET @EndPage = @StartPage + (@PageSize) - 1;
WITH ResultSet As (select
ROW_NUMBER() OVER (order by d.DocumentID) AS 'RowNumber',
d.DocNumber, dt.Name as DocumentTypesName, d.Date, p.Name as PartnersName, dd.SalePrice, dd.VAT, (dd.SalePrice + dd.VAT) as TotalSum
from [dbo].[Documents] d join [dbo].[DocumentTypes] dt on d.TypeID = dt.TypeID
join [dbo].[Partners] p on d.PartnerID = p.PartnerID
join [dbo].[DocumentDetails] dd on d.DocumentID = dd.DocumentID
where ((@StartDate is null) or (d.Date >= @StartDate))
and ((@EndDate is null) or (d.Date <= @EndDate))
and ((@DocumentType is null) or (dt.Name = @DocumentType))
--and ((@Partners is null) or (p.Name = @Partners))
and ((@Partners is null) or (p.Name in (select * from dbo.fnSplitString(@Partners, ','))))
and ((@PriceFrom is null) or (dd.SalePrice >= @PriceFrom))
and ((@PriceTo is null) or (dd.SalePrice <= @PriceTo))
and ((@VATFrom is null) or (dd.VAT >= @VATFrom))
and ((@VATTo is null) or (dd.VAT <= @VATTo))
)
Select * from ResultSet rs WHERE RowNumber between @StartPage and @EndPage
ORDER BY rs.Date ASC
END
しかし、その後、私は、複数の「パートナー」でフィルタを作るために持っていたことが分かった:ここにある(例:Partner1の、Partner2の、...)。それから、SPパラメータ@Partnersを別々の文字列に分割した関数を書いた。しかし、私が "where"節の古い部分をコメントして(関数を呼び出す)関数を呼び出すと、次のエラーメッセージが表示されました: "Cyrillic_General_CI_AS"と "Cyrillic_General_CS_AS"の照合の競合を解決できません操作。"私はSPを実行しようとしました。そして、エラーは行26にあります。 SET @StartPage =((@ PageNumber-1)* @PageSize)+1; と私はそこに何も変更されていません。私は照合についてここで見つけたいくつかのmatirialsを読んだが、私はまだ自分のために問題を把握することはできません。私が書いた関数は次のとおりです。
ALTER FUNCTION [dbo].[fnSplitString]
(
@string NVARCHAR(MAX),
@delimiter CHAR(1)
)
RETURNS @output TABLE(splitdata NVARCHAR(200)
)
BEGIN
DECLARE @start INT, @end INT
SELECT @start = 1, @end = CHARINDEX(@delimiter, @string)
WHILE @start < LEN(@string) + 1 BEGIN
IF @end = 0
SET @end = LEN(@string) + 1
INSERT INTO @output (splitdata)
VALUES(SUBSTRING(@string, @start, @end - @start))
SET @start = @end + 1
SET @end = CHARINDEX(@delimiter, @string, @start)
END
RETURN
END
助けてください。
あなたが最新しようとしたSP –
を投稿することができますが、私は最初のSPとの唯一の違いはコメント部分である、それを掲載しますWHERE句で指定します。 – ppetyr