Hi:
I have the following query, can somebody help me?
SELECT
s.Id, s.Name
FROM
Switch s
INNER JOIN
SwitchTelephoneRange r ON s.Id = r.Id
WHERE
'1526858' BETWEEN FromTelephone AND ToTelephone
Where the '1526858' is a phone number.
My problem is, I want to run the above query for each record in :
select Telephone from PhoneDirectory
So, each telephone number in the second phone, would macth the ' ' in the first query.
How can I do so? Do I need a loop? a cursor? Can you help please?
Thanks
Sounds like you need a correlated sub-query. Seehere andhere for more help.|||Maybe something like this?
SELECT
s.Id, s.Name
FROM
Switch s
INNER JOIN
SwitchTelephoneRange r ON s.Id = r.Id
INNER JOIN
PhoneDirectory pd ON pd.Telephone BETWEEN FromTelephone AND ToTelephone
Thanks for all.
Darek, your way is the best.
How can I join on a table without specifying that a key = key ?
You just joined on a table to get the phone number from and said
"inner join ... ON telephon between"
Can you explain that to me please?
That was a great tip.
Thanks a lot.
|||Thanks.
Everything afterON inJOIN clause is nothing more like simply conditions.
You can write something like that:
FROM a
inner join b.SomeVarChar LIKE a.SomeOtherVarChar
Previous query in ther way:
SELECT
s.Id, s.Name
FROM
Switch s
INNER JOIN
SwitchTelephoneRange r
INNER JOIN
PhoneDirectory pd
WHERE
s.Id = r.Id
AND pd.Telephone BETWEEN FromTelephone AND ToTelephone
No comments:
Post a Comment