Jump to content

sql help


vj5

Recommended Posts

Can someone please check my sql statement and tell what is wrong:

$sql = 'SELECT UCASE(ph.groupno) as groupno, ph.name, ph.asof, p.managing_broker_id, 				 				ph.base, ph.current, ph.`gro/decline`				FROM database1`. Policies p INNER JOIN `database2`.persHorizon ph ON p.GroupNumber = ph.groupno				INNER JOIN dbBkrPol.Brokers b ON p.managing_broker_id = b.PersonID where 1';if (strlen($groupno)!=0) {$sql = $sql." AND `groupno` LIKE '%".$groupno."%'";}if (strlen($groupname)!=0) {$sql = $sql." AND `name` LIKE '%".$groupname."%'";}if (strlen($asofstart)!=0) {$sql = $sql." AND `asof` LIKE '%".$asofstart."%'";}if (strlen($asofend)!=0) {$sql = $sql." AND `asof` LIKE '%".$asofend."%'";}$sql = $sql." GROUP BY `asof` DESC";

Link to comment
Share on other sites

FROM database1`. Policies p
Thank you I corrected. Now I am getting the result set. I echoed the sql and posted in the database, it works there but it isn't working the web page I am working.echoed sql:
SELECT UCASE(ph.groupno) as groupno, ph.name, ph.asof, p.managing_broker_id, ph.base, ph.current, ph.`gro/decline` FROM `database1`.Policies p INNER JOIN `database2`.persHorizon ph ON p.GroupNumber = ph.groupno INNER JOIN Brokers b ON p.managing_broker_id = b.PersonID where 1 GROUP BY `asof` DESC

Link to comment
Share on other sites

There's no difference between running a query on the database or through PHP, it will do the same thing.
Why I am not getting this part when I am echoeing?if (strlen($groupno)!=0) {$sql = $sql." AND `groupno` LIKE '%".$groupno."%'";}if (strlen($groupname)!=0) {$sql = $sql." AND `name` LIKE '%".$groupname."%'";}if (strlen($asofstart)!=0) {$sql = $sql." AND `asof` LIKE '%".$asofstart."%'";}if (strlen($asofend)!=0) {$sql = $sql." AND `asof` LIKE '%".$asofend."%'";}I am searching on groupno, groupname, etc
Link to comment
Share on other sites

Below is the echoed sql query:

SELECT UCASE(ph.groupno) as groupno, ph.name, ph.asof, p.managing_broker_id, ph.base, ph.current, ph.`gro/decline` FROM `dbBkrPol`.Policies p INNER JOIN `dbBkrPol`.persHorizon ph ON p.GroupNumber = ph.groupno INNER JOIN dbBkrPol.Brokers b ON p.managing_broker_id = b.PersonID where 1 AND `groupno` LIKE '%0095A%' AND `name` LIKE '%virtual%' GROUP BY `asof` DESC

Link to comment
Share on other sites

Archived

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

×
×
  • Create New...