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. Web Development
  3. ASP.NET
  4. inserting values from select query

inserting values from select query

Scheduled Pinned Locked Moved ASP.NET
databasehelptutorial
5 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.
  • D Offline
    D Offline
    dj rock
    wrote on last edited by
    #1

    hi guys i have one insert query in which i am selecting values from another table and then insert it in first table Query is like this. usergroup(userid,groupid) group(groupid,groupname,owner) i have values of userid and groupname when i am inserting new group. So i have to also insert values in usergroup table because owner is also member of group. insert into usergroup(userid,groupid) values (userid,select groupid from group where groupname="temp")) it is not working so if anyone knows how to do it please help me out DJ

    G 1 Reply Last reply
    0
    • D dj rock

      hi guys i have one insert query in which i am selecting values from another table and then insert it in first table Query is like this. usergroup(userid,groupid) group(groupid,groupname,owner) i have values of userid and groupname when i am inserting new group. So i have to also insert values in usergroup table because owner is also member of group. insert into usergroup(userid,groupid) values (userid,select groupid from group where groupname="temp")) it is not working so if anyone knows how to do it please help me out DJ

      G Offline
      G Offline
      Guffa
      wrote on last edited by
      #2

      Use a select in the insert. Example: insert into Table2 (SomeField, AnotherField) select @SomeData, AnotherField from Table1 where SomeId = @SomeId

      --- b { font-weight: normal; }

      D 1 Reply Last reply
      0
      • G Guffa

        Use a select in the insert. Example: insert into Table2 (SomeField, AnotherField) select @SomeData, AnotherField from Table1 where SomeId = @SomeId

        --- b { font-weight: normal; }

        D Offline
        D Offline
        dj rock
        wrote on last edited by
        #3

        thanks for your answer i have tried this but i dont have stored procedure and i want to fetch data from table and both data are coming from different table so tell me some other solution

        G 1 Reply Last reply
        0
        • D dj rock

          thanks for your answer i have tried this but i dont have stored procedure and i want to fetch data from table and both data are coming from different table so tell me some other solution

          G Offline
          G Offline
          Guffa
          wrote on last edited by
          #4

          You don't need a stored procedure to do that.

          --- b { font-weight: normal; }

          D 1 Reply Last reply
          0
          • G Guffa

            You don't need a stored procedure to do that.

            --- b { font-weight: normal; }

            D Offline
            D Offline
            dj rock
            wrote on last edited by
            #5

            hey done it thank you so much i thought @somedata will be from stored procedure Thanks man :-D;)

            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