当我将类型传递给存储的文件时,任何想法都会忽略日期
ALTER PROCEDURE [dbo].[hms_GetBenefitsByDateType]
(
@id int,
@startDate datetime,
@EndDate datetime,
@bType int
)
AS
SET NOCOUNT ON;
SELECT benefit.emp_no, benefit.record_id, benefit.contract_id, benefit.career_id, benefit.date_from, benefit.date_to, benefit.benefit_type, benefit.monthly_value, benefit.benefit_provider, benefit.level_of_cover, benefit.current_benefit, benefit.previous_monthly_cost, benefit.benefit_change_details, benefit.notes, benefit.level_description, benefit.monthly_annual, benefit.cover_level, benefit.qualifying_reason, benefit_type.desc_
FROM benefit INNER JOIN
benefit_type ON benefit.benefit_type = benefit_type.code
WHERE (benefit.benefit_type = @bType) or (benefit.emp_no = @id) and (benefit.date_from >= @startDate) and (benefit.date_to <= @EndDate)
其中日期为2006-01-01 00:00:00.000,日期为1900-01-01 00:00:00.000
产生的结果如下
11,4,21,123,2006-01-01 00:00:00.000,1900-01-01 00:00:00.000,3,15.00,1,2.00,1,0.00,无,备注,儿童,1,1, 1,医疗保险 - 儿童
12,6,14,27,2013-06-21 00:00:00.000,2013-06-21 00:00:00.000,3,500.00,0,0.00,1,0.00,
答案 0 :(得分:1)
我会选择像这样的地方
WHERE (benefit.benefit_type = @bType) or (benefit.emp_no = @id) and ( (benefit.date_from >= @startDate) and (benefit.date_to <= (@EndDate + 1)) )
#UPDATE 1
WHERE (benefit.benefit_type = @bType) or (benefit.emp_no = @id) and ( (benefit.date_from IS NULL or benefit.date_from >= @startDate) and ( benefit.date_to IS NULL or benefit.date_to <= (@EndDate + 1)) )
答案 1 :(得分:0)
我也认为你的问题在于哪里的条件。我认为你应该添加更多的括号,以使条件更清晰。对于前者,您可以尝试以下(希望我做对了)
WHERE ((benefit.benefit_type = @bType) OR (benefit.emp_no = @id)) and
((benefit.date_from >= @startDate) and (benefit.benefit_type <= @EndDate))