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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.