Jump to content

Dynamic Select - Need Advice


threeowadmin

Recommended Posts

Hey everyone, thanks in advance for viewing my post. Any insight you might have would be great. I need to figure out the best way to create a select statement which dynamically selects from one of two tables based on a date value.  I can do this in php but for performance purposes i am constrained to solve it using sql only. The sql statement i need to modify is shown below. I need to switch in between tblfacprice and tbloldfacprice based on tickethdrid.datecreated. Any ideas?

 

$sql = "select ponumberline
			, tbltickethdr.tickethdrid
                , tbltickethdr.datecreated
			, tbltickethdr.distributorid as distributorid1
			, tblticketline.startdate as linestartdate
			, tblticketline.enddate as lineenddate
			, tblticketline.invoicedthrudate
			, tblticketline.invoicedthrudate as lineinvoicedthru
			, tblticketline.catalogid
			, tblticketline.catalogid as cid
			, tblticketline.*
			, tbltickethdr.*
			, tblcatalog.*
			, tblfacprice.*
			from tblticketline 
			  join tbltickethdr  using(tickethdrid) 
			  join tblcatalog using (catalogid) 
			  left join tblfacprice on (tblcatalog.catalogid = tblfacprice.catalogid and facagreementid = $agreementid) 
			where facilityid = $facilityid 
                                  and tbltickethdr.tickettype <> 'consignment'
			  and (tblticketline.invoicedthrudate is null or (tblticketline.invoicedthrudate <= '".changeDateFormateInMysqlSupport($enddate) ."' and tblticketline.invoicedthrudate<coalesce(tblticketline.enddate, now()))) 
			  and tblticketline.startdate <= '" .changeDateFormateInMysqlSupport($enddate)."'
			  and tblticketline.voided is null
			  and tblticketline.latevoided is null
			  and tbltickethdr.voided is null
			  and tblticketline.datecreated>='2006-01-01'
			  and (tbltickethdr.invoicedthrudate is null or tbltickethdr.invoicedthrudate < '" .changeDateFormateInMysqlSupport($enddate) . "')
			order by tbltickethdr.distributorid
			";

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.