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. Dynamic Query for XML?

Dynamic Query for XML?

Scheduled Pinned Locked Moved Database
databasexmlquestion
5 Posts 3 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.
  • K Offline
    K Offline
    kasimmohamed
    wrote on last edited by
    #1

    Hi all, DECLARE @DocsList nvarchar(max); SELECT @DocsList = STUFF( (SELECT ', ' + quotename(Particulars) FROM [101_SalaryParticulars] GROUP BY Particulars ORDER BY Particulars FOR XML PATH('')) , 1, 2, ''); I wants to change the above query dynamically. My table name will vary like '[102_SalaryParticulars]','[103_SalaryParticulars]' Etc.,

    Software Engineer AcSys IT Software Solution

    M 1 Reply Last reply
    0
    • K kasimmohamed

      Hi all, DECLARE @DocsList nvarchar(max); SELECT @DocsList = STUFF( (SELECT ', ' + quotename(Particulars) FROM [101_SalaryParticulars] GROUP BY Particulars ORDER BY Particulars FOR XML PATH('')) , 1, 2, ''); I wants to change the above query dynamically. My table name will vary like '[102_SalaryParticulars]','[103_SalaryParticulars]' Etc.,

      Software Engineer AcSys IT Software Solution

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

      kasimmohamed wrote:

      '[102_SalaryParticulars]','[103_SalaryParticulars]'

      Then you deserve all the horror you are going to get with such a terrible design. You should have 1 table with different key for 102 and 103!

      Never underestimate the power of human stupidity RAH

      L 1 Reply Last reply
      0
      • M Mycroft Holmes

        kasimmohamed wrote:

        '[102_SalaryParticulars]','[103_SalaryParticulars]'

        Then you deserve all the horror you are going to get with such a terrible design. You should have 1 table with different key for 102 and 103!

        Never underestimate the power of human stupidity RAH

        L Offline
        L Offline
        Lost User
        wrote on last edited by
        #3

        Mycroft Holmes wrote:

        You should have 1 table with different key for 102 and 103

        I agree with your point, but it is not uncommon to see such design in OLAP databases.

        L M 2 Replies Last reply
        0
        • L Lost User

          Mycroft Holmes wrote:

          You should have 1 table with different key for 102 and 103

          I agree with your point, but it is not uncommon to see such design in OLAP databases.

          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #4

          It's also common to vary the query from code, and not try and do this in the database-server.

          Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^]

          1 Reply Last reply
          0
          • L Lost User

            Mycroft Holmes wrote:

            You should have 1 table with different key for 102 and 103

            I agree with your point, but it is not uncommon to see such design in OLAP databases.

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

            And if he is mucking around with OLAP databases and can't work out how to concatenate a string then they have bigger problems!

            Never underestimate the power of human stupidity RAH

            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