Re: Insert Multiple Rows into a Table Without Using Select



On Wed, 28 Sep 2005 10:59:03 -0700, RitaG wrote:

>Hi.
>
>I want to insert 4 rows into a SQL table.
>Can I do this without using 4 Insert statements?
>
>This is my SQL statement:
> Insert Into MyTable Values (1,2)
> (3,4)
> (5,6)
> (7,8)
>but I'm getting a compile error.
>I tried using a comma after each row (except the last) but that didn't work.

Hi Rita,

The subject suggests that you don't want to use SELECT (why??); if
that's the case, you'll have to use 4 INSERT .. VALUES statements.

Here's how to do it in one INSERT .. SELECT, using UNION:

INSERT INTO MyTable (Column1, Column2)
SELECT 1, 2
UNION ALL
SELECT 3, 4
UNION ALL
SELECT 5, 6
UNION ALL
SELECT 7, 8

Best, Hugo
--

(Remove _NO_ and _SPAM_ to get my e-mail address)
.



Relevant Pages

  • Re: UNION of two SELECT extremely slow
    ... I've localized the problem and it is about UNION operation. ... Another way to help the SQL statement is to remove the subquery, ... The inline view only needs to be resolved once, ... VW.SUPERCATEGORY_ID AS PARENTID, ...
    (comp.databases.oracle.misc)
  • Re: Querying a dataset
    ... > Rep, Area, Period, Qty. ... > I want to display this data on a datagrid like: ... just glancing at your sql statement. ... > UNION ALL ...
    (microsoft.public.dotnet.languages.vb)
  • Re: Import .csv question
    ... I found that the SQL statement that you ... > UNION ... > Sub ImportOneFile(FileSpec As String) ... > Dim strFolder As String ...
    (microsoft.public.access.externaldata)
  • Error Message - Help Needed
    ... I'm trying to use a sql statement in an asp page. ... I have 2 separate statements that work, but I'm trying to UNION them. ... FROM AS SumOfSDAEXP ... The tables that end in A are doing current sales, the table that ends in B is doing historical sales, both have EXACTLY the same column names. ...
    (microsoft.public.sqlserver.programming)
  • Re: Need someone to look at SQL statement FIXED THE PROBLEM
    ... >> UNION ... If I copy just the bottom portion below the second UNION ... >> into the SQL statement it runs perfectly. ...
    (microsoft.public.access.queries)