Joining a query across servers using Zend_Db and SQL Server
In SQL Server there is a syntax for joining a query across two servers where you use the following:
SELECT
SUM(StatsTotal) AS ChannelTotal
FROM [SERVER\DB4_1].DBNAME.dbo.Stats AS Stats
This means that I can connect to one server and then ask the query to execute on another server using a feature of SQL Server called 'linked servers'. My problem is that in Zend_Db
there is no way to use this feature that I can see with Zend_Db_Select
.
Currently I'm trying to use the following code:
$select = $this->d开发者_开发百科b->select();
$select->from(array('Stats' => '[SERVER\DB4_1].DBNAME.dbo.Stats'), array('ChannelTotal' => new Zend_Db_Expr('SUM(StatsTotal)')));
echo $select->assemble();
Which gives me the following SQL in response:
SELECT SUM(StatsTotal) AS "ChannelTotal" FROM "[SERVER\DB4_1]"."DBNAME" AS "Stats"
Obviously this will not work, so is there an alternative way to do this without having to hand-write these queries?
Using 'Stats' => new Zend_Db_Expr('[SERVER\DB4_1].DBNAME.dbo.Stats')
should work.
精彩评论