troubleshooting Question

Cross Database table join in C++

Avatar of nvenable
nvenable asked on
System Programming
10 Comments1 Solution325 ViewsLast Modified:
This is a question that has stumped me for the longest time. I really hope
someone out there has done this before, or can help.

I need to execute a cross database query in my C++ program. We have
SQLServer 2000 and a db connection set up from our computer. My query looks
something like this:

"DELETE FROM files WHERE SUBSTRING(name, (LEN(name) - CHARINDEX('\',
REVERSE(name)) +2), 16) IN (SELECT filename FROM customers..jobs WHERE status
= 'BCD')"

The ‘..’ in the above query is supposed to switch databases… this whole
query runs fine in AQT and if executed from our web servers. However, I am
unsure how to make my C++ program execute the query.

I have:

CDatabase m_db;
CRecordset rs ( &m_db );

...

m_db.OpenEx ( "DSN=myDatabase1;UID=xxxxx;PWD=xxxxxx\0");

...

try
{
m_db.ExecuteSQL ( sql_string ); // where sql_String is the query above
}

Basically, I am trying to cross a table from myDatabase1 with a table from
the customers database. But I don't see a way that m_db can connect to 2
different databases at once.

Does anyone here know how to do this?  Is there a way to associate m_db with 2 different databases at once so the join can be done?

Thank you all.
ASKER CERTIFIED SOLUTION
AndyAinscow
Freelance programmer / Consultant

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 1 Answer and 10 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 10 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros