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. Query Help

Query Help

Scheduled Pinned Locked Moved Database
databasehelpquestion
3 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.
  • J Offline
    J Offline
    Jaffer Mumtaz
    wrote on last edited by
    #1

    Hi, I have the following query

    SELECT iAccountID,iViolatorID,Count(iViolatorID) FROM tbTempQNotificationRequest (NOLOCK)
    WHERE IsProcessed = 0 AND sdtStatusDate >= @sdtCurrentDate AND sdtStatusDate < @sdtCurrentDate + 1
    GROUP BY iAccountID,vcGroupByValue,iViolatorID

    Is it possible say when I group by the result set return iAccount|iViolatorID|Count 1-------|1----------|3 2-------|2----------|5 I would like to have a fourth column say AccountNo and I want that it should contain comma seperated values of AccountNo against the group by columns.e.g. iAccount|iViolatorID|Count|AcccountNo 1-------|1----------|3----|X12,X23,X34 2-------|2----------|5----|X45,X56,X65,X32,X98 I hope my question is clear and understandable

    B 1 Reply Last reply
    0
    • J Jaffer Mumtaz

      Hi, I have the following query

      SELECT iAccountID,iViolatorID,Count(iViolatorID) FROM tbTempQNotificationRequest (NOLOCK)
      WHERE IsProcessed = 0 AND sdtStatusDate >= @sdtCurrentDate AND sdtStatusDate < @sdtCurrentDate + 1
      GROUP BY iAccountID,vcGroupByValue,iViolatorID

      Is it possible say when I group by the result set return iAccount|iViolatorID|Count 1-------|1----------|3 2-------|2----------|5 I would like to have a fourth column say AccountNo and I want that it should contain comma seperated values of AccountNo against the group by columns.e.g. iAccount|iViolatorID|Count|AcccountNo 1-------|1----------|3----|X12,X23,X34 2-------|2----------|5----|X45,X56,X65,X32,X98 I hope my question is clear and understandable

      B Offline
      B Offline
      bcozican
      wrote on last edited by
      #2

      One way to do this is to create a function where you pass in an id that returns a comma seperated string of account numbers for that ID. Then your query would look something like SELECT iAccountID, iViolatorID, Count(iViolatorID), GetAccountNumbers(iViolatorID) AS AccountNos FROM tbTempQNotificationRequest This will slow down the query a bit but it'll work. Hope this helps.

      J 1 Reply Last reply
      0
      • B bcozican

        One way to do this is to create a function where you pass in an id that returns a comma seperated string of account numbers for that ID. Then your query would look something like SELECT iAccountID, iViolatorID, Count(iViolatorID), GetAccountNumbers(iViolatorID) AS AccountNos FROM tbTempQNotificationRequest This will slow down the query a bit but it'll work. Hope this helps.

        J Offline
        J Offline
        Jaffer Mumtaz
        wrote on last edited by
        #3

        Hi, Thanks for the answer. You know i could call a function but the thing is this query is a part of function being called from stored procedure. My scenario is complex and calling another function will effect the procedure performance further as currently procedure takes 5 seconds to execute. So I was looking for something if we could accomplish it through SQL. Though thanks anyways. Regards,

        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