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
...
예, 당신의 대답은 멋진 덕분이다. –