Re: Odd pivot table type query
From: Vishal Parkar (REMOVE_THIS_vgparkar_at_yahoo.co.in)
Date: 11/24/04
- Previous message: aaron kempf: "Re: SQL problems"
- In reply to: Shawn: "Re: Odd pivot table type query"
- Messages sorted by: [ date ] [ thread ]
Date: Wed, 24 Nov 2004 13:06:53 +0530
Shawn,
There is no function as such which will do the things for you.
You may try following approach using User defined function. But remember,
this is not a documented method, so it can not be reliable under all
cirumstances.
CREATE FUNCTION EmpPhones (@ID INT)
RETURNS VARCHAR(8000)
AS
BEGIN
DECLARE @str VARCHAR(1000)
SELECT @str = ISNULL(@str + ',', '') + cats
FROM tab WHERE id = @ID
RETURN (@str)
END
-- sample data / result set.
if object_id ('tab') is not null
drop table tab
go
create table tab(ID int,
cats varchar(50))
go
insert into tab values(1 ,'1-001')
insert into tab values(1 ,'2-002')
insert into tab values(1 ,'3-003')
insert into tab values(2 ,'1-011')
insert into tab values(3 ,'1-012')
insert into tab values(3 ,'2-022')
go
--And then you would call this UDF from within a SELECT statement, as
follows:
select distinct id,dbo.empphones(id) 'comma seperated value' from tab
-- Vishal Parkar vgparkar@yahoo.co.in | vgparkar@hotmail.com
- Previous message: aaron kempf: "Re: SQL problems"
- In reply to: Shawn: "Re: Odd pivot table type query"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|
|