Solved

Teradata Query Assistance

Posted on 2013-11-21
6
545 Views
Last Modified: 2013-11-21
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

0
Comment
Question by:codyvance1
  • 3
  • 2
6 Comments
 
LVL 42

Expert Comment

by:pcelba
ID: 39667638
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

0
 

Author Comment

by:codyvance1
ID: 39667661
TO be honest, someone else created this and is no longer available to troubleshoot..
0
 
LVL 13

Assisted Solution

by:magarity
magarity earned 150 total points
ID: 39667760
I think the problem is the UNION ON in the join should just be ON.

The 'SEC' = 'Res Chg' will work - that's Teradata's column aliasing at work in the third element of the UNION statement on line 5.
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 42

Accepted Solution

by:
pcelba earned 350 total points
ID: 39667767
So the final result could be:

SELECT TOP 500 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%'
 ORDER BY l.DateCreated DESC;

Open in new window

The removed UNION part was in the command for some future extensions planned.
0
 

Author Closing Comment

by:codyvance1
ID: 39667778
Thanks that worked
0
 
LVL 42

Expert Comment

by:pcelba
ID: 39667785
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.
0

Featured Post

Guide to Performance: Optimization & Monitoring

Nowadays, monitoring is a mixture of tools, systems, and codes—making it a very complex process. And with this complexity, comes variables for failure. Get DZone’s new Guide to Performance to learn how to proactively find these variables and solve them before a disruption occurs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Shadow IT is coming out of the shadows as more businesses are choosing cloud-based applications. It is now a multi-cloud world for most organizations. Simultaneously, most businesses have yet to consolidate with one cloud provider or define an offic…
Many companies are looking to get out of the datacenter business and to services like Microsoft Azure to provide Infrastructure as a Service (IaaS) solutions for legacy client server workloads, rather than continuing to make capital investments in h…
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question