MSSQL使用WHERE加入下面的两个表

时间:2014-03-27 18:22:28

标签: php sql

如何使用WHERE加入下面的两个表? 我尝试了以下但我认为我没有正确地做到这一点:

$query = mssql_query('SELECT T_EQ.[ID],T_ASSIGNED.[ID] FROM [TestTABLE].[dbo].[T_ASSIGNED] WHERE [T_ASSIGNED].[A_T_N]="' . $contact_lastname .'" JOIN T_EQ ON T_ASSIGNED.[ID] = T_EQ.[ID]');

此问题是对此处提出的问题的扩展:MS SQL Conversion failed when converting the varchar value to data type int and JOIN two Tables

1 个答案:

答案 0 :(得分:0)

它应该像

$query = mssql_query('SELECT T_EQ.[ID],T_ASSIGNED.[ID] FROM [TestTABLE].[dbo].[T_ASSIGNED] JOIN T_EQ ON T_ASSIGNED.[ID] = T_EQ.[ID] WHERE [T_ASSIGNED].[A_T_N]="' . $contact_lastname .'" );