Solved

substring join

Posted on 2006-11-21
12
520 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

 
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

Turn Insights into Action

Communication across every corner of your business is essential to increase the velocity of your application delivery and support pipeline. Automate, standardize, and contextualize your communication processes with xMatters.

Question has a verified solution.

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

This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
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.
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function

719 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