Select Statement

B

Bob Day

Using vs.2003, vb.net, sql native...

As an example, I have a 3 column table (Dialing_Rules_RBOC), 1 row, all
Integers.
....
fld_IX_Area_Code_Calling_To(value is 317)
fld_IX_Prefix_Range_Begin(value is 0)
fld_IX_Prefix_Range_End(value is 999)
....

Now I want to write a select statement that would see if there is a row that
corresponds to area code 317 and prefix 555. I am using query builder to do
this, because I am a novice at SQL. But I think it you can give me the
select statement, I can build it in the query builder.

Although awkward, the following select statement works:
SELECT fld_Dialing_Rules_RBOC_Table_ID, fld_IX_Area_Code_Calling_To,
fld_IX_Prefix_Range_Begin, fld_IX_Prefix_Range_End

FROM Dialing_Rules_RBOC

WHERE (fld_IX_Area_Code_Calling_To = @AREA_CODE) AND
(fld_IX_Prefix_Range_Begin <= @PREFIX_RANGE_BEGIN) AND
(fld_IX_Prefix_Range_End >= @PREFIX_RANGE_END)

I refer to it as awkward, because you must set the begin and end parameters
below to the same number:
Where @AREA_CODE = 317
@PREFIX_RANGE_BEGIN = 555
@PREFIX_RANGE_END = 555

I there a better way to do it?

Thanks!
Bob Day
 
K

Kevin Yu

Hi Bob,

The query statement is quite good. If you want to query a range of prefix
by this statement, you have to set begin and end parameters. However if
your query is dedicated to query a single prefix, you can write your code
like the following.

SELECT fld_Dialing_Rules_RBOC_Table_ID, fld_IX_Area_Code_Calling_To,
fld_IX_Prefix_Range_Begin, fld_IX_Prefix_Range_End

FROM Dialing_Rules_RBOC

WHERE (fld_IX_Area_Code_Calling_To = @AREA_CODE) AND
(fld_IX_Prefix_Range_Begin <= @PREFIX) AND
(fld_IX_Prefix_Range_End >= @PREFIX)

If anything is unclear, please feel free to reply to the post.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top