Get Combine Records from SQL SERVER with Distinct and comma Separated columns -


i have 3 tables.

  1. group
  2. extension
  3. extention_group (is middle table having groupid , extensionid reference ids)

i have 3 queries i'm using right now,

query getting distinct items extention_group table on basis of groupid

select distinct groupid extention_group order groupid 

query getting required required columns tables

select g.id groupid, g.name groupname, eg.extentionid [group] g  inner join extention_group eg on eg.groupid = g.id   inner join userprofile on eg.extentionid = up.userprofileid 

and query getting extensions csv (comma separated values)

select substring( (select ',' + up.extension userprofile order up.extension xml path('')),2,200000) csvextension 

queries executing perfectly

what want combine of these results single table. how can combine these 3 results in 1 single table, can use easily. have tried unions no success.

it can combine this,

 select g.id groupid, g.name groupname, up.extension, eg.extentionid ,stuff((select ',' + up.extension userprofile up1  xml path('')),1,1,'') csvextension ,eg1.groupid [distinct groupid]  [group] g   inner join extention_group eg on eg.groupid = g.id   inner join userprofile on eg.extentionid = up.userprofileid inner join (select distinct groupid extention_group ) eg1 on eg.groupid=eg1.groupid 

knowing exact relation , data can optimizing it.i don't know how behave.may should remove clause "xml path select"


Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -