Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
jung1975
Aged Yak Warrior
503 Posts |
Posted - 2006-10-02 : 14:46:25
|
I have a query like below SELECT CH.CLAIM_NUM, CH.UNIT_NUM, CH.PERSONAL_NUM, CH.INSURANCE_NUM_P, FROM ra.CLAIM_HEADER CH WHERE (CH.CLAIM_STATUS IN ('M', 'C')) AND (CH.CLAIM_POSTING_DATE BETWEEN @startdate AND @enddate)-----------and have a table called Unit ( join by unit_num with Claim_haeder table)unit_num region_num2058 12060 12713 12563 12726 12728 12755 12756 12754 12727 12720 12715 22716 22719 22780 22779 22778 22777 22776 22775 22774 22749 22748 22745 22739 22738 22737 21933 32751 32752 32750 31827 32714 32622 31822 31593 3--------------------------------- I want to be able to run the query for either the whole region( region 1,2, and 3) or only one region ( i.e region 1 - under region 1 there are 2058,2060 ,2713, 2563, 2726 ,2728 ,2755, 2756 ,2754 , 2727 ,2720 unit) or just one unit ( i.e 1593) by passing the parameters( @region_num and @unit_num). I was trying to do somethin like belwo ,but i am not quite sure how I can do this in one sql statment. SELECT CH.CLAIM_NUM, CH.UNIT_NUM, CH.PERSONAL_NUM, CH.INSURANCE_NUM_P, FROM ra.CLAIM_HEADER CH join ra.unit u on i.unit_num = u.unit_num WHERE (CH.CLAIM_STATUS IN ('M', 'C')) and ( u.region_num = 2region_num or @region_num = 9999 ) or ????? AND (CH.CLAIM_POSTING_DATE BETWEEN @startdate AND @enddate) |
|
harsh_athalye
Master Smack Fu Yak Hacker
5581 Posts |
Posted - 2006-10-03 : 00:49:56
|
SELECT CH.CLAIM_NUM, CH.UNIT_NUM, CH.PERSONAL_NUM, CH.INSURANCE_NUM_P,FROM ra.CLAIM_HEADER CHjoin ra.unit u on i.unit_num = u.unit_numWHERE (CH.CLAIM_STATUS IN ('M', 'C'))and ((case when @region_num <> 9999 then case when u.region_num = @region_num then 1 else 0 end else 1 end) or (case when @unit_num <> 9999 then case when u.unit_num = @unit_num then 1 else 0 end else 1 end))AND (CH.CLAIM_POSTING_DATE BETWEEN @startdate AND @enddate) Harsh AthalyeIndia."Nothing is Impossible" |
|
|
|
|
|
|
|