Re: How to do certain task in SQL?

From: Norman Yuan (NotReal_at_NotReal.not)
Date: 01/18/05


Date: Tue, 18 Jan 2005 07:34:40 -0700

I do not question why you have the extra table with exactly the same layout
(columns, I guess). It is very simple the do what you want. Assume, tableA
contains the 15 (or any number of) rows of user inputs and you want to add
all of them of some of them into tableB. You could use this SQL statement:

INERT INTO tableB (Col1,Col2,Col3...)
SELECT Filed1,Field2,Field3...
FROM tableA
WHERE ... /*here the WHERE clause allows you to choose what rows in tableA
being transfered to tableB.

You also can see from above SQL statement, tableA does not have to be the
same structure as tableB. You only need to make sure the fields selected in
SELECT...clause match the fields (field count and data type) those in INSERT
INTO clause.

Since you just moved to SQL Server/MSDE, I'd sit down for a couple of days
to stduy/investigete T-SQL, rather than browse SQL Book on-line for
particular processing.

"Richard Fagen" <no_spam@my_isp.com> wrote in message
news:e6Ad#LQ$EHA.2112@TK2MSFTNGP14.phx.gbl...
> Hi Jim,
>
> I'm not taking it personally, I appreciate you comments :)
>
> I had a feeling that I'd have to use the "select" command to filter the
> record(s) that I want to work with and then to think in terms of 'a set
> of records'.
>
> I have already defined primary keys for my imported DBF files. I know
> how to 'update' information in existing records, but I was browsing the
> 'SQL Book Online' and couldn't find any references on how to combine
> records from multiple tables. I know about the 'join' command, but my
> request is a bit different. Say I had a existing table with 1000
> records and I had the user input information into a similar table with
> 15 new records (exact same layout) and I wanted to merge the two tables
> into one table with 1015 records, how would I do this?
>
> Thanks for the recommendation, I'll check it out. Is it a general book
> or one specific to MS SQL?
>
> Richard
>
>
>
>
> Jim Young wrote:
> > Hi Richard,
> >
> > Don't take this personally, but from the questions you are asking, you
have
> > a bit of a learning curve ahead of you. First you need to stop looking
at
> > SQL data as a list of sequential records. SQL data is retrieved and
> > manipulated as sets of data. There really is no equivalent to "move to
last
> > record" or first record. If you need to update or select a particular
record
> > then you need to define your records with either a primary key or some
other
> > unique contraint on the data and provide the SQL statement that will
extract
> > a distinct record. I suggest that you find a good general book on SQL
and
> > study up on relational database theory. As a recommendation "Data &
> > Databases: Concepts In Practice" by Joe Celko is a very good book that
lays
> > down the basics of relational database design.
> >
> > Jim