SQL Server Performance

Search in Range type table. Help for Query.

Discussion in 'General Developer Questions' started by gmohd, Apr 24, 2008.

  1. gmohd New Member

    Table T1
    RangeFrom RangeTo Code
    2000 2100 21
    3500 4500 25
    4600 4800 22
    5100 5120 42
    ...
    Table T2
    No
    2006
    2015
    2200
    3550
    4400
    4750
    5100
    ...
    Query Result Should be:
    No Code
    2006 21
    2015 21
    2200 0
    3550 25
    4400 25
    4750 22
    5100 42
  2. martins New Member


    select t2.No
    , isnull(t1.Code,0)
    from t2
    left outer join t1 on t2.No between t1.RangeFrom and t1.RangeTo

Share This Page