Solved

Invalid field error

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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
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…
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.

760 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

19 Experts available now in Live!

Get 1:1 Help Now