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 |
stahorse
Yak Posting Veteran
86 Posts |
Posted - 2012-09-21 : 02:09:25
|
Please to resolve this issue.I have this query SELECT(select REB_TAX_RATE from PR_REB_TAX_RATE where EFF_DATE = (select MAX(EFF_DATE) from PR_REB_TAX_RATE group by EFF_DATE having EFF_DATE <= FR.REBATE_PAID_DATE))FROM PR_FUND_REBATES FR And I get error: Subquery returned more than 1 value. This is not permitted when the subquery follows =, !=, <, <= , >, >= or when the subquery is used as an expression.I tried few queries but every one lead to another error.Please help |
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2012-09-21 : 02:49:47
|
[code]SELECT FR.*, TR.REB_TAX_RATEFROM PR_FUND_REBATES FRCROSS APPLY ( SELECT TOP 1 REB_TAX_RATE FROM PR_REB_TAX_RATE x WHERE x.EFF_DATE <= FR.REBATE_PAID_DATE ORDER BY x.EFF_DATE DESC ) TR[/code] KH[spoiler]Time is always against us[/spoiler] |
 |
|
stahorse
Yak Posting Veteran
86 Posts |
Posted - 2012-09-21 : 03:29:14
|
Can you please explain that code to me. |
 |
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2012-09-21 : 04:12:10
|
[code]SELECT FR.*, TR.REB_TAX_RATEFROM PR_FUND_REBATES FRCROSS APPLY ( SELECT TOP 1 REB_TAX_RATE FROM PR_REB_TAX_RATE x WHERE x.EFF_DATE <= FR.REBATE_PAID_DATE ORDER BY x.EFF_DATE DESC ) TR[/code]the CROSS APPLY is a bit similar with the sub-query. Here it gets the latest REB_TAX_RATE based on the REBATE_PAID_DATE of PR_FUND_REBATES KH[spoiler]Time is always against us[/spoiler] |
 |
|
|
|
|