Solved

substring join

Posted on 2006-11-21
12
519 Views
Last Modified: 2009-07-29
I am trying to use substring commands while joining 2 tables.  I am getting the following error.  I am not sure if it is because of the set command or something different.  Here is the command

UPDATE TEMP_ENROLL
SET SECTION_ID = set SECTION_id =  substring('S_',1,2) + RTRIM(SECTION_id.class_subject_cd) + RTRIM(SECTION_ID.CLASS_CATALOG_NBR) + RTRIM(SECTION_ID.CLASS_CLASS_SECTION)
FROM SECTION_ID
WHERE CLASS_NBR = CLASS_CLASS_NBR

any help is appreciated.

Thanks!
0
Comment
Question by:ericsberr
  • 3
  • 3
  • 2
  • +4
12 Comments
 
LVL 29

Expert Comment

by:Nightman
ID: 17989014
UPDATE TEMP_ENROLL
SET SECTION_ID = substring('S_',1,2) + RTRIM(SECTION_id.class_subject_cd) + RTRIM(SECTION_ID.CLASS_CATALOG_NBR) + RTRIM(SECTION_ID.CLASS_CLASS_SECTION)
FROM SECTION_ID
WHERE CLASS_NBR = CLASS_CLASS_NBR
0
 
LVL 14

Expert Comment

by:mherchl
ID: 17989017
try this:

UPDATE TEMP_ENROLL
SET SECTION_ID = SECTION_id =  substring('S_',1,2) + RTRIM(SECTION_id.class_subject_cd) + RTRIM(SECTION_ID.CLASS_CATALOG_NBR) + RTRIM(SECTION_ID.CLASS_CLASS_SECTION)
FROM TEMP_ENROLL join SECTION_ID on CLASS_NBR = CLASS_CLASS_NBR
0
 
LVL 13

Expert Comment

by:Michael_D
ID: 17989023
Try
UPDATE TEMP_ENROLL
SET SECTION_ID =  substring('S_',1,2) + RTRIM(SECTION_id.class_subject_cd) + RTRIM(SECTION_ID.CLASS_CATALOG_NBR) + RTRIM(SECTION_ID.CLASS_CLASS_SECTION)
FROM SECTION_ID
WHERE CLASS_NBR = CLASS_CLASS_NBR


Seems like you have double = set SECTION_id in your code
0
Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

 
LVL 75

Expert Comment

by:Aneesh Retnakaran
ID: 17989029
UPDATE t
SET SECTION_ID = substring('S_',1,2) + RTRIM(class_subject_cd) + RTRIM(CLASS_CATALOG_NBR) + RTRIM(CLASS_CLASS_SECTION)
FROM SECTION_ID
INNER JOIN TEMP_ENROLL t
ON CLASS_NBR = CLASS_CLASS_NBR
   
0
 
LVL 69

Expert Comment

by:Scott Pletcher
ID: 17989034
Don't think I fully understand, but maybe this:

UPDATE TEMP_ENROLL
SET SECTION_ID = 'S_' + RTRIM(SECTION_id.class_subject_cd) + RTRIM(SECTION_ID.CLASS_CATALOG_NBR) + RTRIM(SECTION_ID.CLASS_CLASS_SECTION)
FROM TEMP_ENROLL
INNER JOIN SECTION_ID ON CLASS_NBR = CLASS_CLASS_NBR
0
 
LVL 8

Expert Comment

by:srafi78
ID: 17989041
UPDATE TEMP_ENROLL
SET SECTION_ID  = (Select substring('S_',1,2) + RTRIM(SECTION_id.class_subject_cd) + RTRIM(SECTION_ID.CLASS_CATALOG_NBR) + RTRIM(SECTION_ID.CLASS_CLASS_SECTION)
FROM SECTION_ID
WHERE CLASS_NBR = CLASS_CLASS_NBR)
0
 

Author Comment

by:ericsberr
ID: 17989138
I tried many of these (i think all of them) the message I am getting is
Server: Msg 209, Level 16, State 1, Line 1
Ambiguous column name 'Class_nbr'.
Server: Msg 209, Level 16, State 1, Line 1
Ambiguous column name 'Class_nbr'.

Is that helpful?
0
 
LVL 75

Expert Comment

by:Aneesh Retnakaran
ID: 17989158
UPDATE t
SET SECTION_ID = substring('S_',1,2) + RTRIM(class_subject_cd) + RTRIM(CLASS_CATALOG_NBR) + RTRIM(CLASS_CLASS_SECTION)
FROM SECTION_ID
INNER JOIN TEMP_ENROLL t
ON t.CLASS_NBR = CLASS_NBR
0
 

Author Comment

by:ericsberr
ID: 17989173
Thanks aneeshattingal  buti am still getting this error..

Server: Msg 209, Level 16, State 1, Line 1
Ambiguous column name 'Class_nbr'.
0
 
LVL 13

Accepted Solution

by:
Michael_D earned 500 total points
ID: 17989192
UPDATE TEMP_ENROLL
SET TEMP_ENROLL.SECTION_ID = substring('S_',1,2) + RTRIM(SECTION_ID.class_subject_cd) + RTRIM(SECTION_ID.CLASS_CATALOG_NBR) + RTRIM(SECTION_ID.CLASS_CLASS_SECTION)
FROM SECTION_ID
INNER JOIN TEMP_ENROLL
ON TEMP_ENROLL.CLASS_NBR = SECTION_ID.CLASS_NBR
0
 
LVL 75

Expert Comment

by:Aneesh Retnakaran
ID: 17989198
can u provide the table structure,      



UPDATE t
SET SECTION_ID = substring('S_',1,2) + RTRIM(s.class_subject_cd) + RTRIM(s.CLASS_CATALOG_NBR) + RTRIM(s.CLASS_CLASS_SECTION)
FROM SECTION_ID S
INNER JOIN TEMP_ENROLL t
ON t.CLASS_NBR = S.CLASS_NBR
0
 
LVL 13

Expert Comment

by:Michael_D
ID: 17989250
Thank you for points and grade :)
0

Featured Post

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
SQL: launch actions one before the other 10 22
SSIS with VPN COnnection 2 70
Query Syntax 17 32
T-SQL: New to using transactions 9 19
Introduction SQL Server Integration Services can read XML files, that’s known by every BI developer.  (If you didn’t, don’t worry, I’m aiming this article at newcomers as well.) But how far can you go?  When does the XML Source component become …
Slowly Changing Dimension Transformation component in data task flow is very useful for us to manage and control how data changes in SSIS.
Via a live example, show how to shrink a transaction log file down to a reasonable size.
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.

813 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

14 Experts available now in Live!

Get 1:1 Help Now