This seems to work fine. There is no reason it should change just because it is in a view.
if OBJECT_ID('Something') is not null
drop table Something
GO
create table Something
(
ID int,
Type varchar(10),
Term varchar(10)
)
GO
insert Something
select 1, 'Subject', 'sky' union all
select 2, 'Next', 'earth' union all
select 2, 'Subject', 'video' union all
select 3, 'Test', 'black' union all
select 4, 'Subject', 'white' union all
select 4, 'Subject', 'paper' union all
select 4, 'Forms', 'red' union all
select 4, 'Subject', 'stone' union all
select 5, 'Test', 'head' union all
select 6, 'Subject', 'leg' union all
select 6, 'Subject', 'water'
GO
select * from Something
--here is the code not in a view
SELECT id,
Stuff((SELECT ', ' + Term
FROM Something s2
WHERE s1.id = s2.id
and s2.Type = 'Subject'
ORDER BY s2.Term
FOR XML PATH('')), 1, 1, '') as Result
FROM Something s1
where Type = 'Subject'
GROUP BY id
go
create view MyView as
SELECT id,
Stuff((SELECT ', ' + Term
FROM Something s2
WHERE s1.id = s2.id
and s2.Type = 'Subject'
ORDER BY s2.Term
FOR XML PATH('')), 1, 1, '') as Result
FROM Something s1
where Type = 'Subject'
GROUP BY id
go
select * from myview
_______________________________________________________________
Need help? Help us help you.
Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.
Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.
Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/