Answer the question
In order to leave comments, you need to log in
How to create a view for elements from lists?
The music album for performers has a list of instruments (roles), for example:
Paul McCartney : lead vocals, guitar, bass, piano, hammond organ, drums, timpani, percussion, recorder, flugelhornHow to create a view of unique items from lists?
Mal Evans: backing vocals (2, 6), saxophone (23)
Answer the question
In order to leave comments, you need to log in
CREATE VIEW RoleDivided
AS
SELECT DISTINCT TRIM( value ) AS RoleSingle
FROM AlbumRole
CROSS APPLY STRING_SPLIT( dbo.RoleDelTrack( [Role] ), ',' )
CREATE FUNCTION dbo.RoleDelTrack ( @RL VARCHAR(500) ) RETURNS VARCHAR(500)
WITH EXECUTE AS CALLER
AS
BEGIN
WHILE (CHARINDEX( '(', @RL) > 0 ) BEGIN
SET @RL = TRIM( LEFT( @RL, CHARINDEX( '(', @RL) - 1 ))
+ RIGHT( @RL, LEN( @RL ) - CHARINDEX( ')', @RL ))
END
RETURN @RL
END
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question