Solved

Teradata Query Assistance

Posted on 2013-11-21
6
502 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 41

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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 41

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 41

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Salesforce.com is a cloud-based customer relationship management (CRM) system. In this article, you will learn how to add and map custom lead and contact fields to your Salesforce instance.
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…
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…

708 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now