Solved

Invalid field error

Posted on 2009-05-19
4
177 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 50 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 450 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

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

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

Why is this different from all of the other step by step guides?  Because I make a living as a DBA and not as a writer and I lived through this experience. Defining the name: When I talk to people they say different names on this subject stuff l…
Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.

831 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