2016-06-06 22 views
0

Ich habe eine Tabelle LogPixelCall (Beispiel zwei Reihen):SQL-Server: update alle Zeilen Spalten basierend auf IP

1 d5104006-8a82-4dfe-b6ca-587d25e869e9 1 2 2016-03-07 16:31:41.997 **92.26.242.166** NULL  
2 5a5ffea2-3a70-4138-aeb7-4dd94900ef27 1 2 2016-03-07 17:39:57.557 **185.28.19.174** NULL 

wo bolded ist IP und letzte NULL Feld ist CountryId aus anderen Tisch.

Jetzt habe ich Iplookup Tabelle, wo ich konvertierte IP zu lange übergeben muss (also muss ich diesen Konvertierungsalgorithmus verwenden) und es gibt mir CountryCode (GB, US, AU), dann vergleiche ich CountryCode mit Country-Tabelle, wo ich Länder aufhalte. Ich möchte dann die LogPixelCall-Informationstabelle manuell mit CountryId aktualisieren, da dies vorher fehlte.

Frage: Basierend auf dem bereitgestellten Datenbankschema, wie aktualisiere ich das LogPixelCall CountryId NULL-Feld, wenn ich ClientIp in LogPixelCall kenne, und kann ich IpLookup verwenden, um CountryIsoCode zu erhalten und eine Verbindung mit Country herzustellen?

+3

Was ist Ihre Frage? Haben Sie Beispielcode? –

+1

Welche Art von Datenbank? Ein SQL zum Aktualisieren einer Tabelle aus einer anderen Tabelle kann je nach Datenbanktyp/-version leicht abweichen. – LukStorms

+0

Ich fiel Ihre Frage fehlt einige Erläuterungen, so kann ich nicht wirklich antworten. Aber Ihre Abfrage kann so etwas wie „update lpc suchen Satz lpc.ContryId = ct.Id von LogPixelCall lpc beitreten IpLookUp il auf il. [Von] = IpConvertFunction (lpc.ClientIP) beitreten Land ct auf ct.code = il .ContryIsoCode wo lpc.ContryId null“ist – jean

Antwort

0
update LogPixelCall set CountryId = c.Id 
--select * /*Check first to make sure */ 
from LogPixelCall lpc 
inner join IpLookup ip on lpc.ClientIp between ip.From and ip.To 
inner join Country c on c.Code = ip.CountryIsoCode 
Verwandte Themen