Solved

Invalid field error

Posted on 2009-05-19
4
175 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

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

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

JSON is being used more and more, besides XML, and you surely wanted to parse the data out into SQL instead of doing it in some Javascript. The below function in SQL Server can do the job for you, returning a quick table with the parsed data.
Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
Using examples as well as descriptions, and references to Books Online, show the different Recovery Models available in SQL Server and explain, as well as show how full, differential and transaction log backups are performed
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.

863 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

23 Experts available now in Live!

Get 1:1 Help Now