User Profile

Collapse

Profile Sidebar

Collapse
ChandanM
ChandanM
Last Activity: Sep 26 '13, 05:41 PM
Joined: Sep 25 '13
Location:
  •  
  • Time
  • Show
  • Source
Clear All
new posts

  • ChandanM
    replied to Insert rows into a table by 'With' clause
    in DB2
    Thank you for your efforts. :-)
    See more | Go to post

    Leave a comment:


  • ChandanM
    replied to Insert rows into a table by 'With' clause
    in DB2
    I found a better way to do it, by removing the WITH statement itself.
    Code:
    insert into table1
    (
    select stateid, name, ssn from
    (
    select row_number() over (partition by state) as num, stateid, name, ssn from state_population
    )
    as data
    where num <= 10
    )
    Thanks for your time and help.
    See more | Go to post

    Leave a comment:


  • ChandanM
    replied to Insert rows into a table by 'With' clause
    in DB2
    The version is V6R1M0.
    See more | Go to post

    Leave a comment:


  • ChandanM
    replied to Insert rows into a table by 'With' clause
    in DB2
    The query does not execute and it gives the following error message:

    SQL0199 - Keyword INSERT not expected. Valid tokens: ( SELECT VALUES.
    State:37000,Nat ive:-199,Origin:[IBM][System i Access ODBC Driver][DB2 for i5/OS]
    See more | Go to post

    Leave a comment:


  • ChandanM
    replied to Insert rows into a table by 'With' clause
    in DB2
    Hi Rabbit,

    Sorry I am new to this site, and did not see your posts about formatting the code. Will ensure I format the code part going forward.

    Anyway, the option you have mentioned was tried the very first time before posting this query. That one too isn't working.

    Code:
    with data
    (
    select row_number() over (partition by state) as num, stateid, name, ssn from state_population
    )
    insert
    ...
    See more | Go to post

    Leave a comment:


  • ChandanM
    replied to Insert rows into a table by 'With' clause
    in DB2
    I tried the following 2 alternatives:

    1.
    Code:
    with data
    (
    insert into table1 (stid, pname, pssn)
    (
    select row_number() over (partition by state) as num, stateid, name, ssn from state_population
    )
    select stateid, name, ssn from data where num <= 10
    )
    2.
    Code:
    with data
    insert into table1 (stid, pname, pssn)
    (
    (
    select row_number() over (partition by state)
    ...
    See more | Go to post
    Last edited by Rabbit; Sep 26 '13, 03:47 AM. Reason: Please use [CODE] and [/CODE] tags when posting code or formatted data. Third and final warning.

    Leave a comment:


  • ChandanM
    replied to Insert rows into a table by 'With' clause
    in DB2
    Code:
    insert into table1 (stid, pname, pssn)
    (
    with data
    (
    select row_number() over (partition by state) as num, stateid, name, ssn from state_population
    )
    select stateid, name, ssn from data where num <= 10
    )
    See more | Go to post
    Last edited by Rabbit; Sep 26 '13, 01:10 AM. Reason: Please use [CODE] and [/CODE] tags when posting code or formatted data. Second Warning.

    Leave a comment:


  • ChandanM
    replied to Insert rows into a table by 'With' clause
    in DB2
    Hi Rabbit.

    I m using Query Tool to query the database (DB2 for OS400), and the above query works. However, when I add the insert query on top of it, it throws an error.

    Keyword WITH not expected. Valid tokens: ( SELECT VALUES.
    See more | Go to post

    Leave a comment:


  • ChandanM
    started a topic Insert rows into a table by 'With' clause
    in DB2

    Insert rows into a table by 'With' clause

    Hi,

    I have a database from which I am retrieving first 10 rows for each group using the 'With' table clause.
    e.g
    Code:
    with data
    (
    select row_number() over (partition by state) as num, state id, name, ssn from state_population
    )
    select * from data where num <= 10
    I want to insert the rows retrieved from above query into another table.

    Can someone help me with this?
    ...
    See more | Go to post
    Last edited by Rabbit; Sep 25 '13, 08:50 PM. Reason: Please use [CODE] and [/CODE] tags when posting code or formatted data.
No activity results to display
Show More
Working...