Jump to content

Recommended Posts

Dear team,

I am filtering the data from my database. My query is 

Select distinct P.Number, P.Description, M.[Name] from SubAssembly as SA
inner join PartDrawing as PD
on SA.PartDrawingID = PD.Id
inner join CatalogPartDrawing  as CPD
on PD.Id = CPD.PartDrawingID
inner join [Catalog] as C
on C.ID = CPD.CatalogID
inner join Model as M
on M.ID = C.ModelID
inner join Part as P
on SA.ChildPartID = P.ID and P.Number in(80001619)

My outpiut is 

image.png.7cb9d0672276fba19a53975c6067c3c3.png

 

But i Want the output like belo image,

image.thumb.png.c901180b21dffb04f4693d5a3f4a6b7d.png

 

Can any one pls correct me to get my required output.

Check your SQL reference manual for correct syntax (I'm used to mysql - I haven't used MSSQL since 2010) although I wouldn't be surprised if MSSQL's pathetic function library doesn't contain it.

It's fairly simple to do it in PHP though. Create an array of names for each number the join() them.

PS Looks like the mssql equivalent is STRING_AGG()

image.png.341cd329c6cfcedfd60ce0a9380e058f.png

Dear Barand,

 

Thanks for your guid. I changed the code as per below

Select distinct P.Number, P.Description,STRING_AGG( CAST(M.Name as nvarchar(MAX)),', ') as name  from SubAssembly as SA
inner join PartDrawing as PD
on SA.PartDrawingID = PD.Id
inner join CatalogPartDrawing  as CPD
on PD.Id = CPD.PartDrawingID
inner join [Catalog] as C
on C.ID = CPD.CatalogID
inner join Model as M
on M.ID = C.ModelID
inner join Part as P
on SA.ChildPartID = P.ID and P.Number in(80001619) GROUP BY P.Number, P.Description

I am getting output now.

image.thumb.png.3f93bfa81f4e9d7dac696ff5f402cdad.png

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.