Improve company productivity with a Business Account.Sign Up

x
?
Solved

substring join

Posted on 2006-11-21
12
Medium Priority
?
524 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
A proven path to a career in data science

At Springboard, we know how to get you a job in data science. With Springboard’s Data Science Career Track, you’ll master data science  with a curriculum built by industry experts. You’ll work on real projects, and get 1-on-1 mentorship from a data scientist.

 
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 70

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 2000 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

A proven path to a career in data science

At Springboard, we know how to get you a job in data science. With Springboard’s Data Science Career Track, you’ll master data science  with a curriculum built by industry experts. You’ll work on real projects, and get 1-on-1 mentorship from a data scientist.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

This month, Experts Exchange sat down with resident SQL expert, Jim Horn, for an in-depth look into the makings of a successful career in SQL.
During the weekend, I was asked to investigate into a deadlock in SQL Server 2014. SQL being something I don’t really fancy myself being an expert at, I had to do some refreshing. This article is a collection of my notes.
Viewers will learn how the fundamental information of how to create a table.
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.

601 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