tsql - Get column a and column b through first parameter to last parameter -


i'm newbie on tsql , stuck on problem. can prb? have table below; (use sql 2008 express edt.)

id    col1    col2 1      7      2 2      7      3 3      7      4 4      7      5 5      9      2 6      9      3 7      9      4 8      9      5 9      11     2 10     11     3 11     11     4 12     11     5 

how use select query fetch between 7/3 , 11/2 (both columns , first/last rows included)

sql fiddle

ms sql server 2008 schema setup:

create table yourtable (   id int,   col1 int,   col2 int )  insert yourtable values (1   ,7     ,2), (2   ,7     ,3), (3   ,7     ,4), (4   ,7     ,5), (5   ,9     ,2), (6   ,9     ,3), (7   ,9     ,4), (8   ,9     ,5), (9   ,11    ,2), (10  ,11    ,3), (11  ,11    ,4), (12  ,11    ,5) 

query 1:

select * yourtable (col1 > 7 , col1 < 11) or       (col1 = 7 , col2 >= 3) or       (col1 = 11 , col2 <= 2) 

results:

| id | col1 | col2 | -------------------- |  2 |    7 |    3 | |  3 |    7 |    4 | |  4 |    7 |    5 | |  5 |    9 |    2 | |  6 |    9 |    3 | |  7 |    9 |    4 | |  8 |    9 |    5 | |  9 |   11 |    2 | 

Comments

Popular posts from this blog

Change php variable from jquery value using ajax (same page) -

Pull out data related to my apps from Android Play Store and iOS App Store -

How can I fetch data from a web server in an android application? -