下面的代码将搜索表格并根据硬编码的过滤器提取结果。我已将默认日期设置为2014年以上,直到当前。但是,如果用户动态传递日期范围和位置(Credited Office)并希望结果在这些日期范围和位置内得到结果,我该怎么办。如果用户未输入任何日期,则代码应默认为2014年至3012年的特定日期,并显示所有地区。
SELECT a.[RDT_FileID]
, a.[Master Policy Number]
, a.[Work item /Submission no#]
, a.[Insured Name]
, a.[Issuing Office]
, a.[Issuing Underwriter]
, a.[Product Line]
, a.[Product Line Subtype]
, a.[Current Status]
, a.[Effective Date]
, a.[Expiry Date]
FROM DB1.dbo.View_Property_Rater_Of_Record a
WHERE a.[Master Policy Number] IS NOT NULL
AND a.[Current Status] = 'Bound'
AND a.[RDT_FileID] IS NULL
AND a.[Product Line Subtype] <> '0102-Marine'
AND a.[Effective Date] >= '2014-04-01'
答案 0 :(得分:0)
试试这个
SELECT * FROM
(SELECT a.[RDT_FileID]
, a.[Master Policy Number]
, a.[Work item /Submission no#]
, a.[Insured Name]
, a.[Issuing Office]
, a.[Issuing Underwriter]
, a.[Product Line]
, a.[Product Line Subtype]
, a.[Current Status]
, case when a.[Current Status] = 'Bound' then 1 end as [SomeName]
, a.[Effective Date]
, a.[Expiry Date]
FROM DB1.dbo.View_Property_Rater_Of_Record a
WHERE a.[Master Policy Number] IS NOT NULL
--AND a.[Current Status] = 'Bound'
AND a.[RDT_FileID] IS NULL
AND a.[Product Line Subtype] <> '0102-Marine'
AND a.[Effective Date] >= '2014-04-01')T1
WHERE [SomeName] IS NOT NULL