views:

87

answers:

2

Hi,

I'm using SQL Server and querying it with php. I have a query that selects data based on dates entered.

 $tsql = "SELECT COUNT(tblBackupArchive.StatusID) AS total, tblBackupArchive.StatusID ".
            "FROM tblBackupArchive INNER JOIN ".
            "tblBackup ON tblBackupArchive.BackupID = tblBackup.BackupID ".
            "WHERE (tblBackupArchive.BackupDate BETWEEN '" . $from ."' AND '" . $to . "' ".
            "GROUP BY tblBackupArchive.StatusID, tblBackup.ClientID ".
            "HAVING (tblBackup.ClientID = " . $bmsid . ")";

I'm getting

Incorrect syntax near the keyword 'GROUP'. ) )

The dates are coming from textboxes (jquery calendar) in the format 'dd/mm/yyyy'.

Not sure what it is I'm doing some here :(

Any help most appreciated,

Jonesy

+9  A: 

Your WHERE is missing a ')'.

 "WHERE (tblBackupArchive.BackupDate BETWEEN '" . $from ."' AND '" . $to . "') ".
Rocket
Yep. That's why a good tool for writing your querries should color your parenthesis.
Raveline
Too bad the brackets provide no value to the query in this case.
OMG Ponies
thanks, hate those stupid mistakes!
iamjonesy
+2  A: 

Looks like you are missing the closing parenthesis on your WHERE clause.

Yevgeniy Brikman