Re: Moving Data Without CURSORS or Looping.
From: Keith Kratochvil (sqlguy.back2u_at_comcast.net)
Date: 10/12/04
- Next message: Keith Kratochvil: "Re: Concatenate 2 columns"
- Previous message: Mal .mullerjannie_at_hotmail.com>: "RE: Concatenate 2 columns"
- In reply to: Bob Cannistraci: "Moving Data Without CURSORS or Looping."
- Next in thread: David Portas: "RE: Moving Data Without CURSORS or Looping."
- Messages sorted by: [ date ] [ thread ]
Date: Tue, 12 Oct 2004 11:29:30 -0500
You will need to create an INSERT INTO....SELECT statement for each table
that you want to move.
Example:
INSERT INTO TheNewTable (lines__id, org__cd, ......)
SELECT seasonal_number, org_code, ......
FROM plan_transaction
WHERE ...
You can use the WHERE clause to make sure that you only insert rows that you
want.
The IF check -- you can probably do that with the CASE statement (refer to
SQL Server Books Online - within the SQL Server program group) for more
information on how to use CASE.
If columns need to come from other tables you can JOIN the tables together
within the SELECT portion of the INSERT statement. You could also go back
an UPDATE them after the table has been loaded, but it is probably more
efficient to do it all in one step.
-- Keith "Bob Cannistraci" <Bob Cannistraci@discussions.microsoft.com> wrote in message news:25C77FD5-FCE0-4D0E-A60F-74D81BEEB6EA@microsoft.com... > 46 tables from an old DB need to be moved into a new DB. The transfer is not > always literal. The new tables can contain data from multiple tables from the > old system. Some fields require a check by an IF statment before being > transformed. > > I rather do this using SQL as it is intended to be used and deal with this > task by moving sets. However, as I read the BOL my procedural mind can only > come up with using a cursor to solve this. > > Here is the DDL of one old table mapping to a new table. Is it possible to > move this data without cursors or any type of looping and handle > transformations where needed? > > CREATE TABLE lines --new table > ( > lines__id integer NOT NULL, > org__cd char(10) NULL, > position__cd char(13) NULL, > fund_source__cd char(4) NULL, > wrk_days_per_week smallint NULL, > is_recurring bit NULL, > is_step_up bit NULL, > line_start_date smalldatetime NULL, > line_end_date smalldatetime NULL, > no_of_positions smallint NULL, > budgets__cd char(4) NULL, > entered_by char(7) NULL, > entered_date smalldatetime NULL > ) > > CREATE TABLE plan_transaction > ( > seasonal_number integer, -- lines__id > org_code char(10), -- org__cd > position_code char(13), -- position__cd > line_start_date smalldatetime, -- line_start_date > line_end_date smalldatetime, -- line_end_date > no_of_position smallint, -- no_of_positions > wrk_days_per_week smallint, --wrk_days_per_week > budget_code char(4), -- budgets__cd > fund_source_code char(4), -- fund_source__cd > next_year_ind char(1), -- is_recurring > number_of_steups smallint, -- is_step_up > entered_by char(7), -- entered_by > entered_date smalldatetime, -- entered_by > fiscal_year smallint, -- dropped > position_short_desc char(10), -- dropped > fy_work_days smallint, -- dropped > rate integer, -- dropped > plan_line_status char(1) -- dropped > ) > > Thanks for your help. > > (Sorry if the formatting is screwed up. It looked perfect in the edit window.)
- Next message: Keith Kratochvil: "Re: Concatenate 2 columns"
- Previous message: Mal .mullerjannie_at_hotmail.com>: "RE: Concatenate 2 columns"
- In reply to: Bob Cannistraci: "Moving Data Without CURSORS or Looping."
- Next in thread: David Portas: "RE: Moving Data Without CURSORS or Looping."
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|