SQL Failed
/var/www/html/lawyers.lawyerlegion.com/web2/helpers/db.php @ 447
/var/www/html/lawyers.lawyerlegion.com/web2/listings.php @ 2085


		SELECT 
                `attorneys`.`ID`,
                `attorneys`.`RefID`,
                `attorneys`.`BarNumber`,
                `attorneys`.`FirstName`,
                `attorneys`.`MiddleName`,
                `attorneys`.`LastName`,
                `attorneys`.`AltFirst`,
                `attorneys`.`AltMiddle`,
                `attorneys`.`NameDisplay`,
                `attorneys`.`Suffix`,
                `attorneys`.`SiteUrl`,
                `attorneys`.`LawFirm`,
                `attorneys`.`Phone`,
                `attorneys`.`Description`,
                `attorneys`.`Tagline`, 
                `attorneys`.`IsPro`, 
                `attorney_addresses`.`StreetAddress`,
                `attorney_addresses`.`ExtendedAddress`,
                `attorney_addresses`.`City`,
                `attorney_addresses`.`County`,
                `attorney_addresses`.`State`,
                `attorney_addresses`.`ZipCode`,
                `attorney_addresses`.`Latitude`,
                `attorney_addresses`.`Longitude`, 
                


`attorney_scores`.`Value` + IFNULL(
			LEAST(
				4.00 * 
				(
				SELECT `InGroup`
				FROM `cred_areas`
				WHERE `Attorney` = `attorneys`.`RefID`
				AND (`Practice` = 2 AND `Subpractice` = 25)
				),
				16.00
			),
			0
		)


 + 1.00 *
		(
SELECT IFNULL(SUM(`assoc_priorities`.`Value`), 0)
		FROM `cred_associations`
                LEFT JOIN `assoc_priorities` ON `assoc_priorities`.`Org` = `cred_associations`.`Organization`
                LEFT JOIN `assoc_practices`  ON `assoc_priorities`.`Org` = `assoc_practices`.`Organization`
		WHERE 
                `cred_associations`.`Attorney` = `attorneys`.`RefID`
		AND `assoc_priorities`.`Site` = "lawyers.lawyerlegion.com"
		AND (
                    `assoc_practices`.`Practice` = 2 
                    AND 
                    `assoc_practices`.`Subpractice` = 25)
		    )


 + 24.00 * 
		(
		SELECT IFNULL(SUM(`cred_areas`.`Percentage`) / 100, 0)
		FROM `cred_areas`
		WHERE `Attorney` = `attorneys`.`RefID`
		AND (
                `Practice` = 2 
                    AND 
                `Subpractice` = 25
                    )
		)


 + 2.00 * 
		(
		SELECT IFNULL(SUM(`cred_areas`.`Percentage`) / 100, 0)
		FROM `cred_areas`
		WHERE `Attorney` = `attorneys`.`RefID`
		AND (
                (
                    `Practice` = 2 
                    AND 
                    `Subpractice` = 0
                )
                    )
		)


 + LEAST(
			20.00 * 
			(
			SELECT COUNT(`cred_certifications`.`ID`)
			FROM `cred_certifications`
                        LEFT JOIN `certifications` ON `certifications`.`Code` = `cred_certifications`.`Certification`
			WHERE `cred_certifications`.`Attorney` = `attorneys`.`RefID`
			AND (`certifications`.`Practice` = 2 AND `certifications`.`Subpractice` = 25)
			) + 
			4.00 * 
			(
			SELECT COUNT(`cred_certifications`.`ID`)
			FROM `cred_certifications`
                        LEFT JOIN `certifications` ON `certifications`.`Code` = `cred_certifications`.`Certification`
			WHERE `cred_certifications`.`Attorney` = `attorneys`.`RefID`
			AND (`certifications`.`Practice` = 2 AND `certifications`.`Subpractice` != 25)
			),
			30.00
		)


 + 2.00 * 
		(
		SELECT COUNT(`cred_awards`.`ID`)
		FROM cred_awards
                LEFT JOIN  special_awards ON cred_awards.SpecialAward = special_awards.Code
		WHERE cred_awards.Attorney = attorneys.RefID
		AND (special_awards.Practice = 2 AND special_awards.Subpractice = 25)
		)


 + IFNULL((        
	SELECT SUM(`From_Score`/100.00) as `Value`
	FROM `attorney_endorsements`
	WHERE `attorney_endorsements`.`To` = `attorneys`.`RefID`
	AND (`attorney_endorsements`.Practice = 2 AND `attorney_endorsements`.`Subpractice` = 25)
	),0)


 + (
SELECT LEAST(
                5,
                (
                SELECT COUNT(`UID`)
                FROM `case_results`
                WHERE `case_results`.`Attorney` = `attorneys`.`RefID`
                AND (`case_results`.Practice = 2 AND `case_results`.`Subpractice` = 25)
                )
            )
)


 + (
SELECT LEAST(
            5,
            (
            SELECT COUNT(`cred_federal_courts`.`UID`) * 0.50 
            FROM `cred_federal_courts`
            LEFT JOIN `federal_courts` ON `federal_courts`.`UID` = `cred_federal_courts`.`Court_UID`
            WHERE `cred_federal_courts`.`Attorney` = `attorneys`.`RefID`
            AND 
            (
                (`federal_courts`.`PracticeAreaA` = 2 AND `federal_courts`.`SubPracticeAreaA` = 25)
                OR
                (`federal_courts`.`PracticeAreaB` = 2 AND `federal_courts`.`SubPracticeAreaB` = 25)
            )    
         )
    )
)



 - IF((LawFirm LIKE "%public defender%" OR 
LawFirm LIKE "%prosecutor%" OR 
LawFirm LIKE "%attorney general%" OR 
LawFirm LIKE "%state attorney%" OR 
LawFirm LIKE "%district attorney%"), 30.00, 0)
 AS Score, 



                 `states`.`FullName` as `StateName`    
                 
                
		FROM `attorneys`
                LEFT JOIN `attorney_scores`    ON `attorney_scores`.`Attorney` = `attorneys`.`RefID`
                LEFT JOIN `attorney_addresses` ON `attorney_addresses`.`Attorney` = `attorneys`.`RefID`
                LEFT JOIN `states`             ON `states`.`ID` = `attorney_addresses`.`State`
		WHERE 
(`attorney_addresses`.`State` = )


 AND `attorneys`.`Pending` = 0 
 AND `attorneys`.`Deleted` = 0
 AND `attorneys`.`IsAttorney` = 1

 AND `attorney_scores`.`Site` = "lawyers.lawyerlegion.com"
 AND (
			SELECT COUNT(`cred_areas`.`ID`)
			FROM `cred_areas`
			WHERE `Attorney` = `attorneys`.`RefID`
			AND ((`Practice` = 2 AND (Subpractice = 0 OR Subpractice = 25)))
		) > 0 

 AND (attorney_addresses.ID = (
		SELECT ID
		FROM attorney_addresses
		WHERE 
                `attorney_addresses`.`Attorney` = `attorneys`.`RefID` 
 AND `attorney_addresses`.`State` = '' 
		ORDER BY `attorney_addresses`.`Primary` + CAST(`attorney_addresses`.`State` = '' AS UNSIGNED) * 2 DESC
		LIMIT 1
	)) GROUP BY `attorney_addresses`.`Attorney`


		ORDER BY  `Score` DESC LIMIT 0, 50;

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ') AND `attorneys`.`Pending` = 0 AND `attorneys`.`Deleted` = 0 AND `attorne' at line 177