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 |
|
Sql_forum
Yak Posting Veteran
50 Posts |
Posted - 2011-12-19 : 03:59:52
|
| I have my Data as shown below:ITEMITEM ISSAGE_FRM ISSAGE_TO CESSAGE_FRM CESSAGE_TOE10RINR 0 60 10 10E10RINR 0 0 15 15E10RINR 0 0 20 20E10RINR 0 0 25 25Here CESSAGE is the inputIf suppose my CESSAGE input is 20, i have to return ISSAGE_FRM and ISSAGE_TO corresponding to that Range.. IF ISSAGE_FRM and ISSAGE_TO record is null or Empty, i should return first record of ISSAGE_FRM, ISSAGE_TO (0-60)..Can any one help quicky?? |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2011-12-19 : 04:42:49
|
| [code]SELECT TOP 1 E10RINR,ISSAGE_FRM ,ISSAGE_TOFROM(SELECT E10RINR,ISSAGE_FRM ,ISSAGE_TO,1 AS CatFROM Table tWHERE @Input BETWEEN CESSAGE_FRM AND CESSAGE_TOUNION ALLSELECT *,2FROM(SELECT TOP 1 E10RINR,ISSAGE_FRM ,ISSAGE_TOFROM TableORDER BY ISSAGE_FRM ,ISSAGE_TO )r)mORDER BY Cat[/code]------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
Sql_forum
Yak Posting Veteran
50 Posts |
Posted - 2011-12-19 : 06:25:22
|
| Hi Visakh16,I have tried ur query ... but it is not gving me results exactly i need.I gave input 20 and got the ISSAGE_FRM and ISS_AGE_TO as 0, 0,But what i need is if the values on those rows are 0, i need to get the first record , i.e 0 and 60 record..can u pls help to get tat desired result |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2011-12-19 : 06:29:03
|
quote: Originally posted by Sql_forum Hi Visakh16,I have tried ur query ... but it is not gving me results exactly i need.I gave input 20 and got the ISSAGE_FRM and ISS_AGE_TO as 0, 0,But what i need is if the values on those rows are 0, i need to get the first record , i.e 0 and 60 record..can u pls help to get tat desired result
this is different from what you asked earlier. suddenly you requirement has changed to 0 values from empty.in that case you need to do like thisSELECT TOP 1 E10RINR,ISSAGE_FRM ,ISSAGE_TOFROM(SELECT E10RINR,ISSAGE_FRM ,ISSAGE_TO,1 AS CatFROM Table tWHERE @Input BETWEEN CESSAGE_FRM AND CESSAGE_TOAND ISSAGE_FRM >0 AND ISSAGE_TO>0UNION ALLSELECT *,2FROM(SELECT TOP 1 E10RINR,ISSAGE_FRM ,ISSAGE_TOFROM TableORDER BY ISSAGE_FRM ,ISSAGE_TO )r)mORDER BY Cat ------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
|
|
|
|
|