• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 270
  • Last Modified:

Correct syntax for SQL between-like query

I am trying to structure a query in a stored proc to handle an incoming zip code as follows: zip comes in and I need to search rule table to see if the zip value is between a value in BeginRange column and EndRange column.  So if 77400 comes in and a record exists where BeginRange column is 77890 and EndRange column is 77405, the record is found.  I can't quite see how the BETWEEN clause would work?  Can someone get me unstuck with the correct query syntax?
0
srbentley
Asked:
srbentley
1 Solution
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
this will do:

WHERE EndRange >= 77440
  AND BeginRange <= 77440

OR

WHERE 77440 BETWEEN BeginRange AND EndRange
0
 
Aneesh RetnakaranDatabase AdministratorCommented:
WHERE @ZipValue BETWEEN @BeginRange and @EndRange
0
 
srbentleyAuthor Commented:
I knew that BETWEEN could work with params, but I didn't know you could reverse things  and use it with the column names.  Thanks.
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now