사용자/시스템과 관련된 몇 가지 매개 변수를 기반으로 사용자에게 보낼 SMS 메시지를 결정하는 조회 방법을 작성하려고합니다. 최후의 수단으로 사용될 기본 메시지가 있지만 다양한 매개 변수로 메시지를 무시하는 여러 가지 방법이 있습니다. 지금까지 내가 조회 조회를 위해 가지고있는 것이 있습니다 - 이것을하기위한 더 좋은 방법이 있습니까? 어쩌면 조회가 이것에 대한 올바른 접근법이 아닌가? 내가 가지고있는 쿼리 여기SQL에서 깔끔하게 채워지는 검색 테이블
ID Key CTID SPID DistID CampID Message
1 Help 1 NULL NULL NULL 'This is the default message'
2 Help 1 375 NULL NULL 'This is the SP375 message'
3 Help 1 377 NULL NULL 'This is the SP377 message'
4 Help 1 NULL 13 NULL 'This is the Dist13 message'
5 Help 1 375 13 NULL 'This is the SP375/Dist13 message'
6 Help 1 NULL 13 500 'This is the Dist13/Camp500 message'
7 Help 1 375 13 500 'This is the SP375/Dist13/Camp500 msg'
8 Help 1 NULL NULL 500 'This is the Camp500 help message'
됩니다 :
select
--top 1
*
from MessageLookup ml
where ml.[Key] = @Key
and ml.CampaignTypeID = @CampaignTypeID
and
(
ml.ServiceProviderID = @ServiceProviderID or
ml.ServiceProviderID is null
)
and
(
ml.DistributorID = @DistributorID or
ml.DistributorID is null
)
and
(
ml.CampaignID = @CampaignID or
ml.CampaignID is null
)
order by
CampaignID desc, -- highest precedence lookup param
DistributorID desc,
ServiceProviderID desc -- lowest precedence lookup param
규칙 열이 재미 있습니다. 미래에 조회를 확장 할 수있는 방법을 제공 할 수도 있습니다. (어쨌든 ...) 답변 주셔서 감사합니다. –