Following script will create common separate values (CSV) or common separate list from tables. convert list to table. Following script is below.
CREATE TABLE CommaSeparated
( ID int IDENTITY,
TeamID int,
FirstName varchar(50)
)
-- Load Sample Data
INSERT INTO CommaSeparated VALUES ( 1, 'Maruthi' )
INSERT INTO CommaSeparated VALUES ( 1, 'Siva' )
INSERT INTO CommaSeparated VALUES ( 1, 'Prasad' )
INSERT INTO CommaSeparated VALUES ( 2, 'Parviz' )
INSERT INTO CommaSeparated VALUES ( 2, 'Javadian' )
INSERT INTO CommaSeparated VALUES ( 2, 'P' )
INSERT INTO CommaSeparated VALUES ( 3, 'Amit' )
INSERT INTO CommaSeparated VALUES ( 3, 'Kumar' )
Select * from CommaSeparated
--Retrieve data with semicolon
--Scenario1
SELECT
t1.TeamID,
MemberList = substring((SELECT ( '; ' + FirstName )
FROM CommaSeparated t2
WHERE t1.TeamID = t2.TeamID
ORDER BY
TeamID,
FirstName
FOR XML PATH( '' )
), 3, 1000 )FROM CommaSeparated t1
GROUP BY TeamID
go
--Scenario2
select t1.TeamID,
memberlist=SUBSTRING((select ('; '+FirstName)
from CommaSeparated t2 where t1.teamid=t2.TeamID
order by TeamID,FirstName for xml path('')
),1,1000) from commaseparated t1
group by t1.teamid
Happy Coding!!!!!!!!
Subscribe to:
Post Comments (Atom)
Search This Blog
DAX - Grouping on multiple columns and the count
Please go thorugh the below URL for entire soultion. http://community.powerbi.com/t5/Desktop/DAX-Grouping-on-multiple-columns-and-the-cou...
-
Database is a collection of objects such as table, view, stored procedure, function, trigger, etc. In MS SQL Server, two types of databa...
-
UNION: To select related information from two tables UNION command is used. It is similar to JOIN command. • UNION All: The UNION ALL comm...
-
Created a table called SegmentDetails. It has 2 columns Segment and Details. Segment contains the category name while Details contains the ...
No comments:
Post a Comment