0
私の質問は、スマートな方法でクエリ文字列を改善する方法ですか?T-SQL動的クエリ
DBからパラメータクエリデータを使用する場合は、パラメータがnullの場合は削除されます。
私のクエリ文字列は、以下のお気に入り:
ALTER procedure [dbo].[spQueryDataFromCPREFROM]
@CompanyName varchar(50),
@TestDDL varchar(20),
@TesterName varchar(50),
@DatepickerForTestDate datetime,
@ApplyDate datetime,
@TestTypeDDL varchar(1),
@QueryString nvarchar(max)
as
begin
if @CompanyName is not null
and @TestDDL is not null
and @TesterName is not null
and @DatepickerForTestDate is not null
and @ApplyDate is not null
and @TestTypeDDL is not null
and @QueryString is not null
begin
select @QueryString = 'select * from [dbo].[CPREFROM] as CF where CF.[UNIT_TID] ='+ @CompanyName
+'and CF.[ELIGIBLE_RATING] ='+ @TestDDL
+'and CF.[Name] =' + @TesterName
+'and CF.[CHECKDATE] ='+ @DatepickerForTestDate
+'and CF.[APPLYDATE] =' + @ApplyDate
+'and CF.[A_S] =' + @TestTypeDDL
end
else if @CompanyName is null
and @TestDDL is not null
and @TesterName is not null
and @DatepickerForTestDate is not null
and @ApplyDate is not null
and @TestTypeDDL is not null
and @QueryString is not null
begin
select @QueryString = 'select * from [dbo].[CPREFROM] as CF where CF.[ELIGIBLE_RATING] ='+ @TestDDL
+'and CF.[Name] =' + @TesterName
+'and CF.[CHECKDATE] ='+ @DatepickerForTestDate
+'and CF.[APPLYDATE] =' + @ApplyDate
+'and CF.[A_S] =' + @TestTypeDDL
end
...
はい、あなたの答えは素晴らしいのおかげです。 –