1

複数の条件を持つ基準を表示したいのですが、いずれかの条件がnullであるか、where句での設定方法よりも値がない場合。例:

where
SR.fk_Designation_ID = @pk_Designation_ID
and SR.fk_SeniorityCategory_ID = @pk_SeniorityCategory_ID
and SR.IsCurrent_Appointment = 1 and SR.fk_SeparationType_ID is null
order by Senority_Joining_For_Order,E.Date_Of_Birth

ここで、条件を@pk_SeniorityCategory_ID句にnull含めたくない場合。and SR.fk_SeniorityCategory_ID = @pk_SeniorityCategory_IDwhere

4

1 に答える 1

2

これを試して:

WHERE
SR.fk_Designation_ID = @pk_Designation_ID
AND (@pk_SeniorityCategory_ID IS NULL 
     OR 
     SR.fk_SeniorityCategory_ID = @pk_SeniorityCategory_ID)
AND SR.IsCurrent_Appointment = 1 AND SR.fk_SeparationType_ID IS NULL
ORDER BY Senority_Joining_For_Order,E.Date_Of_Birth
于 2012-06-06T07:04:36.683 に答える