Issue with Aliased Columns in SQL Query 4 Months, 1 Week ago
|
Karma: 0
|
Hello,
I’m encountering an issue with a SQL query where I’m using CONCAT to combine different fields. Here’s a snippet of the query:
Code: |
SELECT
`No`,
CONCAT(Name) AS 'Carrier Name',
`Trade_Name`,
REPLACE(REPLACE(Min, '1.5', 'Restricted'), '5', 'Unrestricted') AS 'Authority Type',
REPLACE(REPLACE(Status, 'A', 'Active'), 'S', 'Suspended') AS Status,
CONCAT(Street, ', ', City, ', ', State, ' ', LEFT(ZIP, 5)) AS Address,
CONCAT('(', LEFT(Telephone, 3), ') ', SUBSTRING(Telephone, 4, 3), '-', RIGHT(Telephone, 4)) AS Telephone
FROM #__tablename
|
The data displays correctly, but when I attempt to sort or search based on the columns (e.g., Address or Telephone, etc), I encounter SQL errors. It appears that the ARI Table is processing the entire CONCAT expression as the column name instead of using the alias.
SQL ERROR: Unknown column 'Carrier Name' in 'where clause'
Could you advise on how to resolve this issue? Is there a way to make the sorting and searching operations work with these calculated columns?
Thanks
|
|
|
Last Edit: 2024/08/14 20:16 By fshehzad.Reason: more info
|
|
Re:Issue with Aliased Columns in SQL Query 4 Months, 1 Week ago
|
Karma: 760
|
Hello,
Try to quote all alias names with '. It will look like:
Code: |
SELECT
`No`,
CONCAT(Name) AS 'Carrier Name',
`Trade_Name`,
REPLACE(REPLACE(Min, '1.5', 'Restricted'), '5', 'Unrestricted') AS 'Authority Type',
REPLACE(REPLACE(Status, 'A', 'Active'), 'S', 'Suspended') AS 'Status',
CONCAT(Street, ', ', City, ', ', State, ' ', LEFT(ZIP, 5)) AS 'Address',
CONCAT('(', LEFT(Telephone, 3), ') ', SUBSTRING(Telephone, 4, 3), '-', RIGHT(Telephone, 4)) AS 'Telephone'
FROM #__tablename
|
If it doesn't help could you reproduce the problem on a test site and provide a temporary access to it by email or send an SQL dump of table with fake data so we can reproduce the problem?
Regards,
ARI Soft
|
|
|
|
|
|