?
Solved

Invalid field error

Posted on 2009-05-19
4
Medium Priority
?
185 Views
Last Modified: 2012-05-07
I have the query below throwing an error about AMS_Ref being an invalid column name. Can anyone shed some light on this please?

Thanx as always for any advice.
SELECT     RIGHT('00' + CAST(a.ARCD11 AS varchar(2)), 2) + '-' + RIGHT('00000' + CAST(a.RCNO11 AS varchar(5)), 5) AS AMS_Ref , b.CustomerNumber
FROM         dbo.SON_Archive4Sentinel_PTP11 AS a LEFT OUTER JOIN
                      ANCHORSERV.S3CUSTDB.dbo.CustomerTable AS b ON SUBSTRING(AMS_Ref, 1, 8) = b.CustomerNumber
WHERE     (a.EVNO11 = 50)

Open in new window

0
Comment
Question by:Steven O'Neill
4 Comments
 
LVL 75

Assisted Solution

by:Aneesh Retnakaran
Aneesh Retnakaran earned 200 total points
ID: 24421544
SELECT     RIGHT('00' + CAST(a.ARCD11 AS varchar(2)), 2) + '-' + RIGHT('00000' + CAST(a.RCNO11 AS varchar(5)), 5) AS AMS_Ref , b.CustomerNumber
FROM         dbo.SON_Archive4Sentinel_PTP11 AS a
LEFT OUTER JOIN  ANCHORSERV.S3CUSTDB.dbo.CustomerTable AS b ON SUBSTRING(RIGHT('00000' + CAST(a.RCNO11 AS varchar(5)), 5), 1, 8) = b.CustomerNumber
WHERE     (a.EVNO11 = 50)
0
 
LVL 57

Accepted Solution

by:
Raja Jegan R earned 1800 total points
ID: 24421554
Hope this helps
SELECT RIGHT('00' + CAST(a.ARCD11 AS varchar(2)), 2) + '-' + RIGHT('00000' + CAST(a.RCNO11 AS varchar(5)), 5) AS AMS_Ref , b.CustomerNumber
FROM dbo.SON_Archive4Sentinel_PTP11 AS a 
LEFT OUTER JOIN ANCHORSERV.S3CUSTDB.dbo.CustomerTable AS b ON SUBSTRING(RIGHT('00' + CAST(a.ARCD11 AS varchar(2)), 2) + '-' + RIGHT('00000' + CAST(a.RCNO11 AS varchar(5)), 5), 1, 8) = b.CustomerNumber
WHERE     (a.EVNO11 = 50)

Open in new window

0
 
LVL 31

Expert Comment

by:RiteshShah
ID: 24421557
try this.

SELECT     RIGHT('00' + CAST(a.ARCD11 AS varchar(2)), 2) + '-' + RIGHT('00000' + CAST(a.RCNO11 AS varchar(5)), 5) AS AMS_Ref , b.CustomerNumber
FROM         dbo.SON_Archive4Sentinel_PTP11 AS a LEFT OUTER JOIN
                      ANCHORSERV.S3CUSTDB.dbo.CustomerTable AS b ON SUBSTRING(a.AMS_Ref, 1, 8) = b.CustomerNumber
WHERE     (a.EVNO11 = 50)
0
 
LVL 2

Author Closing Comment

by:Steven O'Neill
ID: 31582974
Thanx again for this guys, thought I could use the ASM_Ref within the FROM condition but obviously couldn't do this. Have given some points to @aneeshattingal as you were on the right track but the query wasn't complete (missing the first part of the SELECT query whilst within the FROM Condition) and @rrjegan17 had the complete query. Thanx again to all.
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

In the first part of this tutorial we will cover the prerequisites for installing SQL Server vNext on Linux.
What if you have to shut down the entire Citrix infrastructure for hardware maintenance, software upgrades or "the unknown"? I developed this plan for "the unknown" and hope that it helps you as well. This article explains how to properly shut down …
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.
Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.
Suggested Courses

862 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