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.
Author |
Topic |
sqlfresher2k7
Aged Yak Warrior
623 Posts |
Posted - 2012-09-10 : 12:55:06
|
[code]Table:Ipmaster--------------ipid name ip---- ------ ----------------------20 test1 1.12.340.1.123444.3.3.227 test2 1.12.340.1.123444.328 test3 1.12.340.1.123444.3.3Table:Iptrans-------------ID Ip -- -----------------------------------1 1.12.340.1.123444.3.3.2.2.2.12 1.12.340.1.123444.3.3.2.2.2.1.13 1.12.340.1.123444.3.3.2.2.2.1.24 1.12.340.1.123444.3.3.2.2.2.1.35 1.12.340.1.123444.3.3.2.2.2.1.46 1.12.340.1.123444.3.3.2.2.2.1.57 1.12.340.1.123444.3.3.2.2.2.1.6Expected output:ID Ip ipid -- ----------------------------------- -----1 1.12.340.1.123444.3.3.2.2.2.1 202 1.12.340.1.123444.3.3.2.2.2.1.1 203 1.12.340.1.123444.3.3.2.2.2.1.2 204 1.12.340.1.123444.3.3.2.2.2.1.3 205 1.12.340.1.123444.3.3.2.2.2.1.4 206 1.12.340.1.123444.3.3.2.2.2.1.5 207 1.12.340.1.123444.3.3.2.2.2.1.6 20I want a query which should get the ipid from IPmaster for the IPtrans table of transacation records.[/code]Thanks for your help in advance.. |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2012-09-10 : 12:59:49
|
[code]SELECT i.*,t.ipidFROM Iptrans iCROSS APPLY (SELECT TOP 1 ipid FROM Ipmaster WHERE i.Ip LIKE Ip + '%' ORDER BY LEN(Ip) DESC)t[/code]------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
sqlfresher2k7
Aged Yak Warrior
623 Posts |
Posted - 2012-09-10 : 13:38:14
|
Thanks a lot visakh.. |
 |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2012-09-10 : 14:33:20
|
welcome------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
|
|