Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 Query question

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2005-06-28 : 08:35:31
Ron writes "I am having hard time to come up with a query and plese help me figure out if it's possible. Thanks in advance!


I have two tables.

<Table A>
IP_ID IP_ADDR
1 192.168.100.1
2 192.168.100.2
3 192.168.100.3
4 192.168.100.4
5 192.168.100.5
6 192.168.100.6
7 192.168.100.7
8 192.168.100.8
9 192.168.100.9
10 192.168.100.10


<Table B>
T_ID E_NAME S_ID T_ID
1 ping 2 7
2 telnet 5 6
3 telnet 6 2
4 telnet 2 3
5 ping 2 3
6 ssh 5 4
7 ftp 6 7

From the above two tables, I would like to have the following results. Instead of showing "S_ID" as just a number, I would like to show the IP address from "TABLE A" where "IP_ID" = "S_ID". And for "T_ID", it will do the same. See the expected result below.

Expected result

ID ENAME SOURCE_IP TARGET_IP
1 ping 192.168.100.2 192.168.100.7
2 telnet 192.168.100.5 192.168.100.6
3 telnet 192.168.100.6 192.168.100.2
4 telnet 192.168.100.2 192.168.100.3
5 ping 192.168.100.2 192.168.100.3
6 ssh 192.168.100.5 192.168.100.4
7 ftp 192.168.100.6 192.168.100.7


Thanks.

Ron"

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2005-06-28 : 08:55:26
Try this

Select T1.T_Id,T1.E_NAME,T2.IP_ADDRE, T2.IP_ADDRE from TableA T1 inner join Table2
on T2.S_Id=T1.IP_Id and T2.T_Id=T1.IP_ID


Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -