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. SQL QUERY

SQL QUERY

Scheduled Pinned Locked Moved Database
databasesql-serversysadminhelpquestion
9 Posts 4 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.
  • G Offline
    G Offline
    girijeshkumar
    wrote on last edited by
    #1

    plz help me am begginner to ms sql server my question mulitple rowwise data should be display to one columnwise suppose from table1 i created column like empname,reference table2 i created column like reference and salary details join both table retrieve and display empname, reference,and all salary details for particular employee in one column table1 value -----------------------------| empname | referenceno -----------------------------| girijesh | 111 -----------------------------| ajay | 121 -----------------------------| table2 value -----------------------------------------------------| referenceno | salary -----------------------------------------------------| 111 | jan-10000 -----------------------------------------------------| 111 | feb-20000 -----------------------------------------------------| 111 | mar-30000 -----------------------------------------------------| 121 | jan-10000 -----------------------------------------------------| 121 | feb-20000 -----------------------------------------------------| so now result like below -----------------------------------------------------| empname | reference | salary -----------------------------------------------------| girijesh | 111 | jan-10000,feb-20000,mar-30000 -----------------------------------------------------| ajay | 121 | jan-10000,feb-20000 -----------------------------------------------------| i want query to display like above result

    I B R 3 Replies Last reply
    0
    • G girijeshkumar

      plz help me am begginner to ms sql server my question mulitple rowwise data should be display to one columnwise suppose from table1 i created column like empname,reference table2 i created column like reference and salary details join both table retrieve and display empname, reference,and all salary details for particular employee in one column table1 value -----------------------------| empname | referenceno -----------------------------| girijesh | 111 -----------------------------| ajay | 121 -----------------------------| table2 value -----------------------------------------------------| referenceno | salary -----------------------------------------------------| 111 | jan-10000 -----------------------------------------------------| 111 | feb-20000 -----------------------------------------------------| 111 | mar-30000 -----------------------------------------------------| 121 | jan-10000 -----------------------------------------------------| 121 | feb-20000 -----------------------------------------------------| so now result like below -----------------------------------------------------| empname | reference | salary -----------------------------------------------------| girijesh | 111 | jan-10000,feb-20000,mar-30000 -----------------------------------------------------| ajay | 121 | jan-10000,feb-20000 -----------------------------------------------------| i want query to display like above result

      I Offline
      I Offline
      i j russell
      wrote on last edited by
      #2

      https://www.simple-talk.com/sql/t-sql-programming/concatenating-row-values-in-transact-sql/[^]

      G 1 Reply Last reply
      0
      • G girijeshkumar

        plz help me am begginner to ms sql server my question mulitple rowwise data should be display to one columnwise suppose from table1 i created column like empname,reference table2 i created column like reference and salary details join both table retrieve and display empname, reference,and all salary details for particular employee in one column table1 value -----------------------------| empname | referenceno -----------------------------| girijesh | 111 -----------------------------| ajay | 121 -----------------------------| table2 value -----------------------------------------------------| referenceno | salary -----------------------------------------------------| 111 | jan-10000 -----------------------------------------------------| 111 | feb-20000 -----------------------------------------------------| 111 | mar-30000 -----------------------------------------------------| 121 | jan-10000 -----------------------------------------------------| 121 | feb-20000 -----------------------------------------------------| so now result like below -----------------------------------------------------| empname | reference | salary -----------------------------------------------------| girijesh | 111 | jan-10000,feb-20000,mar-30000 -----------------------------------------------------| ajay | 121 | jan-10000,feb-20000 -----------------------------------------------------| i want query to display like above result

        B Offline
        B Offline
        Bernhard Hiller
        wrote on last edited by
        #3

        The function you need is called PIVOT. See e.g. http://blogs.msdn.com/b/spike/archive/2009/03/03/pivot-tables-in-sql-server-a-simple-sample.aspx[^]

        G 1 Reply Last reply
        0
        • G girijeshkumar

          plz help me am begginner to ms sql server my question mulitple rowwise data should be display to one columnwise suppose from table1 i created column like empname,reference table2 i created column like reference and salary details join both table retrieve and display empname, reference,and all salary details for particular employee in one column table1 value -----------------------------| empname | referenceno -----------------------------| girijesh | 111 -----------------------------| ajay | 121 -----------------------------| table2 value -----------------------------------------------------| referenceno | salary -----------------------------------------------------| 111 | jan-10000 -----------------------------------------------------| 111 | feb-20000 -----------------------------------------------------| 111 | mar-30000 -----------------------------------------------------| 121 | jan-10000 -----------------------------------------------------| 121 | feb-20000 -----------------------------------------------------| so now result like below -----------------------------------------------------| empname | reference | salary -----------------------------------------------------| girijesh | 111 | jan-10000,feb-20000,mar-30000 -----------------------------------------------------| ajay | 121 | jan-10000,feb-20000 -----------------------------------------------------| i want query to display like above result

          R Offline
          R Offline
          ritesh gupta5555
          wrote on last edited by
          #4

          select t1.empname,t1.referenceno,t2.salary from table1 t1 join table2 t2 on t1.referenceno=t2.refereceno

          G 1 Reply Last reply
          0
          • R ritesh gupta5555

            select t1.empname,t1.referenceno,t2.salary from table1 t1 join table2 t2 on t1.referenceno=t2.refereceno

            G Offline
            G Offline
            girijeshkumar
            wrote on last edited by
            #5

            its show answer like below -----------------------------------| empname | reference | salary -----------------------------------| girijesh | 111 | jan-10000 -----------------------------------| girijesh | 111 | feb-20000 -----------------------------------| girijesh | 111 | mar-30000 -----------------------------------| ajay | 121 | jan-10000 -----------------------------------| ajay | 121 feb-20000 -----------------------------------| this wat if i executed ur query i got but i want reslut like below see ur ouput and wat am accepted output so now result like below -----------------------------------------------------| empname | reference | salary -----------------------------------------------------| girijesh | 111 | jan-10000,feb-20000,mar-30000 -----------------------------------------------------| ajay | 121 | jan-10000,feb-20000 -----------------------------------------------------| i want query to display like above result

            R 1 Reply Last reply
            0
            • I i j russell

              https://www.simple-talk.com/sql/t-sql-programming/concatenating-row-values-in-transact-sql/[^]

              G Offline
              G Offline
              girijeshkumar
              wrote on last edited by
              #6

              in query u put case statement 1,2,3 like that but problem is reference number should chage every time wat to do ... then how to retrieve the data..

              I 1 Reply Last reply
              0
              • B Bernhard Hiller

                The function you need is called PIVOT. See e.g. http://blogs.msdn.com/b/spike/archive/2009/03/03/pivot-tables-in-sql-server-a-simple-sample.aspx[^]

                G Offline
                G Offline
                girijeshkumar
                wrote on last edited by
                #7

                plz gothrough it and plz understand my concept and solve it.. bcoz u not properly understand my output

                1 Reply Last reply
                0
                • G girijeshkumar

                  in query u put case statement 1,2,3 like that but problem is reference number should chage every time wat to do ... then how to retrieve the data..

                  I Offline
                  I Offline
                  i j russell
                  wrote on last edited by
                  #8

                  Read the section on 'Concatenating values when the number of items is not known'.

                  1 Reply Last reply
                  0
                  • G girijeshkumar

                    its show answer like below -----------------------------------| empname | reference | salary -----------------------------------| girijesh | 111 | jan-10000 -----------------------------------| girijesh | 111 | feb-20000 -----------------------------------| girijesh | 111 | mar-30000 -----------------------------------| ajay | 121 | jan-10000 -----------------------------------| ajay | 121 feb-20000 -----------------------------------| this wat if i executed ur query i got but i want reslut like below see ur ouput and wat am accepted output so now result like below -----------------------------------------------------| empname | reference | salary -----------------------------------------------------| girijesh | 111 | jan-10000,feb-20000,mar-30000 -----------------------------------------------------| ajay | 121 | jan-10000,feb-20000 -----------------------------------------------------| i want query to display like above result

                    R Offline
                    R Offline
                    ritesh gupta5555
                    wrote on last edited by
                    #9

                    Use sort by or group by with the query to get the result.

                    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