Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Database & SysAdmin
  3. Database
  4. Update a flag based on portion of data avialble in other column

Update a flag based on portion of data avialble in other column

Scheduled Pinned Locked Moved Database
helptutorialannouncement
6 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Y Offline
    Y Offline
    yuvachandra
    wrote on last edited by
    #1

    Hi, Could some one help me with loading the TABLE2 like the way it is shown below. SELECT COL1, COL2 FROM TABLE1 COL1 COL2 1 Tier 1 (QL) (ST) (PA) 2 Tier 2 (QL) (ST) 3 Tier 1 (ST) 4 Tier 1 (ST) (PA) 5 Tier 1 ----------------------------------------------------- INSERT INTO TABLE2 (COL1,COL2,QTY_FLG,STP_THPY_FLG,PRIOR_AUTHN_FLG) SELECT COL1,COL2, , , FROM TABLE1 ------------------------------------------------------ SELECT * FROM TABLE2 COL1 COL2 QL_FLG ST_FLG PA_FLG 1 Tier 1 (QL) (ST) (PA) 1 1 1 2 Tier 2 (QL) (ST) 1 1 0 3 Tier 1 (ST) 0 1 0 4 Tier 1 (ST) (PA) 0 1 1 5 Tier 1 0 0 0 Basically from Table1(COL1, COL2) i want to copy data to Table2(Col1,Col2)..while inserting, i want check if COL2 is having any specification ((QL) (ST) (PA)) accoringly flag should be updated with 1 to the respective _FLG column,if there is no specility (example : 5th row) all the _FLG columns should be updated with 0. Please let me know if there are any related posts. Thanks

    M 1 Reply Last reply
    0
    • Y yuvachandra

      Hi, Could some one help me with loading the TABLE2 like the way it is shown below. SELECT COL1, COL2 FROM TABLE1 COL1 COL2 1 Tier 1 (QL) (ST) (PA) 2 Tier 2 (QL) (ST) 3 Tier 1 (ST) 4 Tier 1 (ST) (PA) 5 Tier 1 ----------------------------------------------------- INSERT INTO TABLE2 (COL1,COL2,QTY_FLG,STP_THPY_FLG,PRIOR_AUTHN_FLG) SELECT COL1,COL2, , , FROM TABLE1 ------------------------------------------------------ SELECT * FROM TABLE2 COL1 COL2 QL_FLG ST_FLG PA_FLG 1 Tier 1 (QL) (ST) (PA) 1 1 1 2 Tier 2 (QL) (ST) 1 1 0 3 Tier 1 (ST) 0 1 0 4 Tier 1 (ST) (PA) 0 1 1 5 Tier 1 0 0 0 Basically from Table1(COL1, COL2) i want to copy data to Table2(Col1,Col2)..while inserting, i want check if COL2 is having any specification ((QL) (ST) (PA)) accoringly flag should be updated with 1 to the respective _FLG column,if there is no specility (example : 5th row) all the _FLG columns should be updated with 0. Please let me know if there are any related posts. Thanks

      M Offline
      M Offline
      Mycroft Holmes
      wrote on last edited by
      #2

      Looking at your example it is not possible to identify the col1/2 content. Assuming the fist number is not in col1 I would break it into 2 queries The first query should group by the col1 and count the instances of the different specifications. The second query should build the string based on that information.

      Never underestimate the power of human stupidity RAH

      Y 1 Reply Last reply
      0
      • M Mycroft Holmes

        Looking at your example it is not possible to identify the col1/2 content. Assuming the fist number is not in col1 I would break it into 2 queries The first query should group by the col1 and count the instances of the different specifications. The second query should build the string based on that information.

        Never underestimate the power of human stupidity RAH

        Y Offline
        Y Offline
        yuvachandra
        wrote on last edited by
        #3

        Hi, Thank you so much for your reply. Could you please find the table information clearly with each row and data separated with pipe delimeter (|). As you suggested, Group the column by Col1.. As the Col1 Information is unique.. i think it will give the same data even after grouping. SELECT COL1, COL2 FROM TABLE1 COL1|COL2 1| Tier 1 (QL) (ST) (PA) 2| Tier 2 (QL) (ST) 3| Tier 1 (ST) 4| Tier 1 (ST) (PA) 5| Tier 1 ----------------------------------------------------- INSERT INTO TABLE2 (COL1,COL2,QL_FLG,ST_FLG,PA_FLG) SELECT COL1,COL2, , , FROM TABLE1 ------------------------------------------------------ SELECT * FROM TABLE2 COL1| COL2| QL_FLG| ST_FLG| PA_FLG 1| Tier 1 (QL) (ST) (PA)| 1 |1| 1 2| Tier 2 (QL) (ST)| 1 |1| 0 3| Tier 1 (ST)| 0 |1 |0 4| Tier 1 (ST) (PA)| 0| 1| 1 5| Tier 1 |0 |0 |0

        M 1 Reply Last reply
        0
        • Y yuvachandra

          Hi, Thank you so much for your reply. Could you please find the table information clearly with each row and data separated with pipe delimeter (|). As you suggested, Group the column by Col1.. As the Col1 Information is unique.. i think it will give the same data even after grouping. SELECT COL1, COL2 FROM TABLE1 COL1|COL2 1| Tier 1 (QL) (ST) (PA) 2| Tier 2 (QL) (ST) 3| Tier 1 (ST) 4| Tier 1 (ST) (PA) 5| Tier 1 ----------------------------------------------------- INSERT INTO TABLE2 (COL1,COL2,QL_FLG,ST_FLG,PA_FLG) SELECT COL1,COL2, , , FROM TABLE1 ------------------------------------------------------ SELECT * FROM TABLE2 COL1| COL2| QL_FLG| ST_FLG| PA_FLG 1| Tier 1 (QL) (ST) (PA)| 1 |1| 1 2| Tier 2 (QL) (ST)| 1 |1| 0 3| Tier 1 (ST)| 0 |1 |0 4| Tier 1 (ST) (PA)| 0| 1| 1 5| Tier 1 |0 |0 |0

          M Offline
          M Offline
          Mycroft Holmes
          wrote on last edited by
          #4

          Ok so this is not structured data it is rubbish, you are going to have to parse col2 of table1 into proper data. Then create a normalised table where you have 3 records for 1|Tier1. After that it is a positional or possibly a pivot. OR You can create a cursor spit to process each record into the desired table2 format by parsing the col2 of table1.

          Never underestimate the power of human stupidity RAH

          Y 1 Reply Last reply
          0
          • M Mycroft Holmes

            Ok so this is not structured data it is rubbish, you are going to have to parse col2 of table1 into proper data. Then create a normalised table where you have 3 records for 1|Tier1. After that it is a positional or possibly a pivot. OR You can create a cursor spit to process each record into the desired table2 format by parsing the col2 of table1.

            Never underestimate the power of human stupidity RAH

            Y Offline
            Y Offline
            yuvachandra
            wrote on last edited by
            #5

            HI, Thank you for the reply. Actaully the data is pretty much structered... since i cannot able to show the data here with proper horizantal and vertical bars,i kept Pipe delimeter so that data of each column will be separate from each other. My source table is having rows in arround 500 - 600K using a cursor will be costly in performence point of view. Could u please suggest if there is any other alternative.

            Y 1 Reply Last reply
            0
            • Y yuvachandra

              HI, Thank you for the reply. Actaully the data is pretty much structered... since i cannot able to show the data here with proper horizantal and vertical bars,i kept Pipe delimeter so that data of each column will be separate from each other. My source table is having rows in arround 500 - 600K using a cursor will be costly in performence point of view. Could u please suggest if there is any other alternative.

              Y Offline
              Y Offline
              yuvachandra
              wrote on last edited by
              #6

              HI, this is how it worked for me INSERT INTO TABLE2 (COL1, COL2, QL_FLG, ST_FLG, PA_FLG) (SELECT COL1, COL2, DECODE(INSTR(COL2,'QL'),0,0,1) QL_FLG, DECODE(INSTR(COL2,'ST'),0,0,1) ST_FLG, DECODE(INSTR(COL2,'PA'),0,0,1) PA_FLG FROM TABLE1); Thank you so much for your help.

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups