View Full Version : creating a dynamic sql statement

11-25-2003, 05:00 PM
I have two recordset in one page, "rslicense" and "rsaddressfromlicense".

rsaddresfromlicense gets in query info from rslicense. I set up varibles that will take in the values from rslicense and use it in the query for rsaddressfromlicense. I just need to know how can I write a sql statement that will take the values in $NUMBER, $STREET, AND $APT, and use it to create the sql statement below.

In Eglish: Select everything from table dog_header where HOUSE_NO is equal to the value in $NUMBER, STREET_NAME is equal to the value in $STREET and APT_NO is equal to the value in $APT;

$NUMBER = $rslicense->Fields('HOUSE_NO')
$STREET = $rslicense->Fields('STREET_NAME')
$APT = $rslicense->Fields('APT_NO')

$query_rsaddressfromlicense = sprintf("SELECT * FROM DOG_HEADER WHERE STREET_NAME = ??????????????????);

11-25-2003, 08:51 PM
If i understand correctly you essentially just wrote it.

$query_rsaddressfromlicense = sprint(select * from DOG_HEADER where HOUSE_NO=$NUMBER & STREET_NAME = $STREET & APT_NO = $APT);

that is all you really need to do, if I understand you correctly. the $vars may need to be enclosed in single or double quotes, it really depends on the value you have the table columns set to.

11-25-2003, 09:12 PM
Exactly what I needed. Great! That Simple Huhh. Thanx