Link to home
Start Free TrialLog in
Avatar of Cody Vance
Cody VanceFlag for United States of America

asked on

Teradata Query Assistance

Can someone assist with this?  I am getting 3706 Syntax error, expected something between ',' and 'LEFT' keyword:

SELECT TOP 500 * 
FROM (SELECT l.CustomerID, l.DateCreated, l.TranType, l.BeforeImage, l.AfterImage, l.Initials, c.LastName 
FROM PROD_STEAKHOUSE_TB.TranLog l
   LEFT OUTER JOIN PROD_STEAKHOUSE_TB.Customer c ON l.CustomerID = c.CustomerID WHERE l.TranType = 'Res Chg' AND c.LastName LIKE 'k%' 
UNION SELECT l.CustomerID, l.Time_Stamp, 'SEC', LEFT(l.ActionContext + N' ' + CASE WHEN l.AuthSuccess = 1 THEN 'Success' 
   ELSE 'Failure' END + N' on ' + l.PhysicalLocation, 255), '', ISNULL(w.WaiterInitials, ''), ISNULL(c.LastName, '') FROM PROD_STEAKHOUSE_TB.SecurityLog AS l 
     LEFT OUTER JOIN PROD_STEAKHOUSE_TB.Waiter w ON l.WaiterID = w.WaiterID 
     LEFT OUTER JOIN PROD_STEAKHOUSE_TB.Customer c UNION ON l.CustomerID = c.CustomerID WHERE  'SEC' = 'Res Chg' AND c.LastName LIKE 'kr%' ) a 
ORDER BY DateCreated DESC;

Open in new window

Avatar of Pavel Celba
Pavel Celba
Flag of Czechia image

I am not Terradata expert but what means  " UNION ON " inside the last LEFT JOIN ?

Also 'SEC' = 'Res Chg'  cannot evaluate to True so the whole command can be reduced to
SELECT TOP 500 * 
FROM (SELECT l.CustomerID, l.DateCreated, l.TranType, l.BeforeImage, l.AfterImage, l.Initials, c.LastName 
FROM PROD_STEAKHOUSE_TB.TranLog l
   LEFT OUTER JOIN PROD_STEAKHOUSE_TB.Customer c ON l.CustomerID = c.CustomerID WHERE l.TranType = 'Res Chg' AND c.LastName LIKE 'k%') a 
ORDER BY DateCreated DESC;

Open in new window

Avatar of Cody Vance

ASKER

TO be honest, someone else created this and is no longer available to troubleshoot..
SOLUTION
Avatar of magarity
magarity

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks that worked
The 'SEC' = 'Res Chg' will work ??

Maybe yes... If the 'SEC' is handled as quoted column name and 'Res Chg' is either quoted column name or string constant. I don't know whether Teradata handles quoted identifiers this mixed way...

I know T-SQL and some MySQL and 'SEC' means a character string constant obviously. It should result into constant value in the third column but quoted column name is also an explanation.

The more exact answer could be possible if we would know your data model.