Click here to Skip to main content
15,889,116 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
how to find the result if have months fixed value from one table by comparing with from months and to months if have table structure like this.

SQL
planid| percentage | frommonths | tomonths 
11       5               12           24
11       6               25           60


how to find result for between frommonths and to months if i have months value like 14
SQL
select from table where planid = 11 and months values lies between 12-25 or 25-60 according to fixed months values
Posted
Updated 17-Nov-14 2:00am
v3

SQL
select * from table where 14(yourmonth) between frommonths and  tomonths 


you can pass yourmonth as variable also

eg.
SQL
declare @yourmonth int
set @yourmonth =14

select * from table where @yourmonth  between frommonths and  tomonths
 
Share this answer
 
v2
Comments
King Fisher 17-Nov-14 7:59am    
better to read if its Formatted :)
Shweta N Mishra 17-Nov-14 8:27am    
thanks.
TRY LIKE THIS

SQL
DECLARE @TEMPTBL TABLE(
ID INT IDENTITY(1,1)
,FROMDMNTHS INT
,TOMONTHS INT
,PERCENTAGE INT
)


INSERT INTO @TEMPTBL
(FROMDMNTHS,TOMONTHS,PERCENTAGE )
SELECT 2,25,5
UNION ALL
SELECT 20,30,15
UNION ALL
SELECT 12,40,25
UNION ALL
SELECT 5,50,35
UNION ALL
SELECT 8,60,45


SELECT * FROM @TEMPTBL

SELECT * FROM @TEMPTBL WHERE FROMDMNTHS BETWEEN 2 AND 5 AND TOMONTHS BETWEEN 5 AND 50
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900