Home » SQL & PL/SQL » SQL & PL/SQL » sql join question
sql join question [message #36050] Thu, 01 November 2001 08:58 Go to next message
Samantha Powell
Messages: 2
Registered: November 2001
Junior Member
How do I do this:

select records from one data source, and insert them into another data source with one statement?

Please help there has got to be a way.
thanks
samantha

----------------------------------------------------------------------
Re: sql join question [message #36051 is a reply to message #36050] Thu, 01 November 2001 09:04 Go to previous messageGo to next message
Sudhakar Atmakuru
Messages: 58
Registered: May 2001
Member
Its simple. Use SELECT statement as a part of INSERT statement. It would like like

INSERT INTO my_table1 SELECT * FROM my_table2;

Good luck :)

----------------------------------------------------------------------
Re: sql join question [message #36053 is a reply to message #36051] Thu, 01 November 2001 09:10 Go to previous messageGo to next message
Samantha Powell
Messages: 2
Registered: November 2001
Junior Member
Here is stmt.

insert into SAT_info (population, avg_math, avg_verbal, admit_term,coll_code, major_code, ethnic_code) select count(*) as recordcount,avg(convert(int,best_sat_verbal)), avg(convert(int,best_sat_math)), admit_term_code,coll_code,major_code,ethnic_code from sisbapp group by admit_term_code,major_code,ethnic_code, coll_code

Table sisbapp is using one source and table academicprofile is in another.

This does not work.

----------------------------------------------------------------------
Re: sql join question [message #36058 is a reply to message #36053] Thu, 01 November 2001 12:16 Go to previous message
Sudhakar Atmakuru
Messages: 58
Registered: May 2001
Member
Try this way:

insert into SAT_info (population, avg_math, avg_verbal, admit_term,coll_code, major_code, ethnic_code) select count(*) as recordcount,convert(int,avg(best_sat_verbal)), convert(int,avg(best_sat_math)), admit_term_code,coll_code,major_code,ethnic_code from sisbapp group by admit_term_code,major_code,ethnic_code, coll_code

This is the one you gave, but I made a little modification in it. Dont give the CONVERT() within an AVG() function. Let it get the result first and then you convert into INT. Hope you understand my point.

Good luck.

----------------------------------------------------------------------
Previous Topic: single quote
Next Topic: Re: DB link in PL/SQL
Goto Forum:
  


Current Time: Fri Apr 19 01:39:37 CDT 2024