Jump to content

mssql_query problems


mkswanson

Recommended Posts

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!

Link to comment
Share on other sites

  • 4 weeks later...

 

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 ";

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.