Hi,
I have a problem with a union statement. I'm trying to use the following statement:
(SELECT tbl1.dnldaccess_id
, 0 AS order_id
, tbl1.product_id
, tbl1.password
, tbl1.download_num
, product_name
, '' AS full_name
, DATE_FORMAT(tbl1.effective_ts,'" . DATEFMT_LONG_DB . "') AS effective_ts
FROM " . $strTblName . " tbl1
, " . TBLSALES_PRODUCT . " tbl3
WHERE tbl1.order_id = 0
AND tbl1.product_id = tbl3.product_id
) UNION (
SELECT tbl1.dnldaccess_id
, tbl1.order_id
, 0 AS product_id
, tbl1.password
, tbl1.download_num
, '' AS product_name
, CONCAT(tbl5.title_abbr,' ',tbl4.first_name,' ',tbl4.last_name) AS full_name
, DATE_FORMAT(tbl1.effective_ts,'" . DATEFMT_LONG_DB . "') AS effective_ts
FROM " . $strTblName . " tbl1
, " . TBLSALES_ORDER . " tbl2
, " . TBLSALES_CUSTOMER . " tbl4
, " . TBLSALES_TITLE . " tbl5
WHERE tbl1.order_id <> 0
AND tbl1.order_id = tbl2.order_id
AND tbl2.customer_id = tbl4.customer_id
AND tbl4.title_id = tbl5.title_id
ORDER BY product_name
, full_name
, tbl1.dnldaccess_id
The problem is that the first query always seems control the width of the the resulting columns no matter which way round I have the statements. So in this format, nothing appears in the full_name column unless I increase the number of spaces in the first select, in which case the resulting field will only be as wide as the number of spaces in the first select. The problem is that the maximum width that full_name can be is 113 characters which is a bit cumbersome to put into the query to say the least and as the resulting column seems to be a fixed width, it is always 113 characters rather than just the width of the data.
The same thing happens with the product_name field when the selects are swapped.
The selects work perfectly standalone, but this quirk only seems to happen when they are combined with the union.
Can anyone suggest a way to stop the union interfering with the column widths, please?
Debbie-Leigh