I'm using PDO to connect to an MS SQL 2000 database and want to create a left join to another database on the same SQL 2000 server. This query returns the correct results when run on the MSSQL query analyser and pulls the data from both databases as I'm expecting.
select t_job.pk_Job, t_JobSummary.Description, t_CarChecks.YesNo
from t_job
left join t_JobSummary on pk_Job=t_JobSummary.fk_Job
left join DATABASE2.dbo.t_CarChecks t_CarChecks on pk_Job=t_CarChecks.fk_Job
where t_JobSummary.Description_vc LIKE \'Cars %\'
However, when I use the same query from the web-page, no results are returned. The query worked from the web-page until I added the LEFT JOIN to the second database and if I comment out that database as shown below, the query returns the results so I can be sure(?!) that the problem lies with the SQL statement.
select t_job.pk_Job, t_JobSummary.Description --, t_CarChecks.YesNo
from t_job
left join t_JobSummary on pk_Job=t_JobSummary.fk_Job
--left join DATABASE2.dbo.t_CarChecks t_CarChecks on pk_Job=t_CarChecks.fk_Job
where t_JobSummary.Description_vc LIKE \'Cars %\'
After reading here and on other sites, I've used an alias for the second database but I still don't get any results.
I'm new to PDO and this has me stumped. Any helpful pointers (or letting me know that there is an obvious mistake here), would be gratefully appreciated.
Thanks!
Thanks for the very quick responses, however, I've found the issue. Completely unrelated to PDO, it was the permissions on the second table in the database. Testing from the SQL Server query analyser retuned the results because I had permissions on the new table; the user I'm using to query the table with PDO did not...
One for the 'Check this before posting on Stack-Overflow again' notebook...