mkswanson Posted September 4, 2009 Share Posted September 4, 2009 I am attempting to run an mssql query and am receiving several errors: Warning: mssql_query() [function.mssql-query]: message: Incorrect syntax near the keyword 'JOIN'. (severity 15) in D:\XAMPP\xampp\htdocs\index.php on line 23 Warning: mssql_query() [function.mssql-query]: message: Incorrect syntax near 'POLLING_DATAON'. (severity 15) in D:\XAMPP\xampp\htdocs\index.php on line 23 Warning: mssql_query() [function.mssql-query]: Query failed in D:\XAMPP\xampp\htdocs\index.php on line The $query is defined as: $query = "SELECT ENTITY_DATA.CustomerName, POLLING_DATA.ProductLine, POLLING_DATA.ProductVersion"; $query .= "FROM ENTITY_DATA INNER JOIN (SELECT row_number() over(partition by EntityID order by PollingID desc) as seq, ProductLine, ProductVersion, EntityID, PollingID FROM POLLING_DATA) POLLING_DATA"; $query .= "ON ENTITY_DATA.EntityID = POLLING_DATA.EntityID"; $query .= "WHERE POLLING_DATA.seq = 1"; With a more simple query (such as SELECT * FROM POLLING_DATA), there is not a problem and the anticipated results are returned. The more advanced query runs fine in SQL, so the problem seems to be with the way it is being interpreted by PHP (or with the syntax I am using). Any help would be much appreciated! Quote Link to comment https://forums.phpfreaks.com/topic/173147-mssql_query-problems/ Share on other sites More sharing options...
darkgr33n Posted October 3, 2009 Share Posted October 3, 2009 The $query is defined as: $query = "SELECT ENTITY_DATA.CustomerName, POLLING_DATA.ProductLine, POLLING_DATA.ProductVersion"; $query .= "FROM ENTITY_DATA INNER JOIN (SELECT row_number() over(partition by EntityID order by PollingID desc) as seq, ProductLine, ProductVersion, EntityID, PollingID FROM POLLING_DATA) POLLING_DATA"; $query .= "ON ENTITY_DATA.EntityID = POLLING_DATA.EntityID"; $query .= "WHERE POLLING_DATA.seq = 1"; Any help would be much appreciated! Is it something as silly as a lack of white space at the end of each addition ? To me, your SELECT would read: SELECT ENTITY_DATA.CustomerName, POLLING_DATA.ProductLine, POLLING_DATA.ProductVersionFROM ENTITY_DATA INNER JOIN (SELECT row_number() over(partition by EntityID order by PollingID desc) as seq, ProductLine, ProductVersion, EntityID, PollingID FROM POLLING_DATA) POLLING_DATA .......ProductVersionFROM ENTITY_DATA...... adding a space at the end may work: $query = "SELECT ENTITY_DATA.CustomerName, POLLING_DATA.ProductLine, POLLING_DATA.ProductVersion "; Quote Link to comment https://forums.phpfreaks.com/topic/173147-mssql_query-problems/#findComment-929721 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.