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. group by and concat dependent rows

group by and concat dependent rows

Scheduled Pinned Locked Moved Database
helpquestion
2 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.
  • L Offline
    L Offline
    Lost User
    wrote on last edited by
    #1

    got a problem: table(with names A, B): A B ---------- 1 Hallo 1 wie geht es dir? 2 schlecht! 3 nein, 3 eigentlich gut! I want the result: A B Resultat C ------------------------------------------- 1----Hallo---------------- 1----wie geht es dir?-----Hallo wie geht es dir? 2----schlecht!------------schlecht! 3----nein,---------------- 3----eigentlich gut!------nein, eigentlich nicht Thank`s for helping!!! nico

    A 1 Reply Last reply
    0
    • L Lost User

      got a problem: table(with names A, B): A B ---------- 1 Hallo 1 wie geht es dir? 2 schlecht! 3 nein, 3 eigentlich gut! I want the result: A B Resultat C ------------------------------------------- 1----Hallo---------------- 1----wie geht es dir?-----Hallo wie geht es dir? 2----schlecht!------------schlecht! 3----nein,---------------- 3----eigentlich gut!------nein, eigentlich nicht Thank`s for helping!!! nico

      A Offline
      A Offline
      airbus380
      wrote on last edited by
      #2

      Try this: First) You must create a "user defined function" (T SQL function) like this CREATE FUNCTION SSum (@a INT) //SSum = string sum RETURNS NVARCHAR(255) AS BEGIN DECLARE @ssum NVARCHAR(255) DECLARE @b NVARCHAR(25) SET @ssum = '' DECLARE crs CURSOR FOR SELECT B FROM table WHERE A = @a OPEN crs FETCH NEXT FROM crs INTO @b WHILE( @@FETCH_STATUS = 0 ) BEGIN SET @ssum = @ssum + '-' + @b FETCH NEXT FROM crs INTO @b END CLOSE crs DEALLOCATE crs IF( LEN(@ssum) != 0 ) SET @ssum = SUBSTRING(@ssum,2,255) RETURN @ssum END Second) Build a SELECT query using SSum function like this: SELECT DISTINCT A , dbo.SSum(A) AS Result FROM table --- object oriented uml oriented iconix oriented sql oriented truespace oriented --- solitare oriented :-)

      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