我正在尝试使用odbc用php连接到sql服务器数据库,它工作正常,然后我更改了sql查询,但出现此错误:
警告:odbc_exec():SQL错误:[Microsoft] [ODBC SQL Server驱动程序] [SQL Server]'。'附近的语法不正确。SQLExecDirect在...中的SQL状态为37000。
我尝试返回正在运行的初始查询,但遇到相同的错误。
我检查了语法,找不到任何内容,并且在sql server management studio上执行时,两个查询都能正常工作。
$dsn2 = "Driver={SQL Server};Server=$servername2;Database=$dbname";
$conn2 = odbc_connect( $dsn2 , $username2 , $password2);
$sql = "SELECT top(1) Ticket.RFC_NUMBER AS [T-N° de ticket]
,Catalog_.[TITLE_FR] AS [T-CI]
,Group_.[GROUP_FR] AS [A-Groupe_Intervenant]
FROM [EVO_DATA50004].[50004].[SD_REQUEST] as Ticket
inner join [EVO_DATA50004].[50004].[AM_ACTION] as Action_ WITH (NOLOCK) on Ticket.[REQUEST_ID] = Action_.[REQUEST_ID]
inner join [EVO_DATA50004].[50004].[SD_CATALOG] as Catalog_ WITH (NOLOCK) on Ticket.[SD_CATALOG_ID] = Catalog_.[SD_CATALOG_ID]
inner join [EVO_DATA50004].[50004].[AM_GROUP] as Group_ WITH (NOLOCK) on Action_.[GROUP_ID] = Group_.group_ID
left outer join [EVO_DATA50004].[50004].AM_EMPLOYEE AS Employee_ WITH (NOLOCK) ON Action_.DONE_BY_ID = Employee_.EMPLOYEE_ID
WHERE Ticket.RFC_NUMBER like 'I%'
AND Action_.END_DATE_UT is null
AND Action_.STATUS_ID_ON_CREATE is not null
AND Action_.STATUS_ID_ON_CREATE in('12')
And Employee_.[LAST_NAME] is null
AND Action_.[group_id] in(42)";
$result = odbc_exec($conn2 , $sql);