Ok heres my scenario - i want to query a local db and store the results of the GUID select query into an array.
i would then like to query the remote server to return a result set which show basically any new records
This is the query but obviously this only works on the same server.
SELECT *
FROM remotetable remote
WHERE NOT EXISTS
(
SELECT 1
FROM localtable local
WHERE local.guid = remote.guid
)
and insert the results of this query into my local db to consolidate it.
so it would be something like
ArrayList myArrayList = new ArrayList();
OdbcConnection local = new OdbcConnection("DSN=local");
local.Open();
OdbcCommand guidSelect = new OdbcCommand("SELECT GUID from localtable",local);
OdbcDataReader DbReader = guidSelect.ExecuteReader();
while (DbReader.Read())
{
String guid = (string)DbReader[0];
myArrayList.Add(guid);
}
local.Close();
OdbcConnection local = new OdbcConnection("DSN=remote");
"SELECT * FROM remotetable remote WHERE NOT EXISTS (SELECT 1 FROM"+ myArrayList() +" local WHERE local.guid = remote.guid)
obviously this will not work as is but it should give a general overview what id like to accomplish
thanks in advance :)
The only way I know how to do this is to actually pass in a table of Guids like this:
string guids = "''" + string.Join("'',''", myArrayList) + "''";
string query = string.format("SELECT * FROM remotetable WHERE NOT id IN ({0})", guids);
In my opinion if you are trying to track for new records, you should just add a sequential column and then just grab everything higher than the MAX of that column on the local side.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.