0

当我将类型传递给存储过程时,任何想法都会忽略日期

 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) 

其中 date from 是 2006-01-01 00:00:00.000 并且 date to 是 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,None ,Notes ,Children ,1,1,1,Medical Cover - Children
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,

4

2 回答 2

1

我会去这样的地方

WHERE (benefit.benefit_type = @bType) or (benefit.emp_no = @id)  and ( (benefit.date_from >= @startDate) and (benefit.date_to <= (@EndDate + 1)) )

#更新 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)) )
于 2013-08-28T09:23:14.570 回答
0

我也认为你的问题在于 where 条件。我认为您应该添加更多括号以使条件更清楚。对于前,您可以尝试以下方法(希望我做对了

WHERE    ((benefit.benefit_type = @bType) OR (benefit.emp_no = @id))  and
((benefit.date_from >= @startDate) and (benefit.benefit_type <= @EndDate))
于 2013-08-28T09:26:29.380 回答