November 2, 2007 at 8:50 am
Ah... just a note... if the concatenation exceeds 8000 characters in SQL Server 2000, there's virtually no chance of displaying the full width of the concatenation and we may have to do something else to get the correct return...
--Jeff Moden
Change is inevitable... Change for the better is not.
November 2, 2007 at 8:57 am
You bet... thanks for the feedback, Eric.
--Jeff Moden
Change is inevitable... Change for the better is not.
November 15, 2007 at 5:10 am
simple but effective solution in sql 2000 , modified to return each case statement result in different column , effectively creating pivot report.thank you
September 10, 2008 at 10:38 am
This is it man. Awesome. The first solution never finished after 7 min with 11000 records and this solution runs in less than "1" yes ONE second...
Thanks for sharing your knowledge. Doesn't matter if you didn't invent it. You shared it!!!
September 10, 2008 at 5:46 pm
anthony.evans (11/15/2007)
simple but effective solution in sql 2000 , modified to return each case statement result in different column , effectively creating pivot report.thank you
If you'd like to see more about this "cross tab" technology in SQL Server 2000, please see the following...
http://www.sqlservercentral.com/articles/T-SQL/63681/
... and thanks for the feedback 🙂
--Jeff Moden
Change is inevitable... Change for the better is not.
November 11, 2008 at 5:37 pm
Thanks for every one.. This topic is really useful for me
November 11, 2008 at 8:27 pm
Raghu Kurella (9/10/2008)
This is it man. Awesome. The first solution never finished after 7 min with 11000 records and this solution runs in less than "1" yes ONE second...Thanks for sharing your knowledge. Doesn't matter if you didn't invent it. You shared it!!!
Thanks for the feedback, Raghu!
--Jeff Moden
Change is inevitable... Change for the better is not.
May 5, 2011 at 8:30 am
I appreciate that this thread is quite old so for forgive me for resurrrecting it.
this is great...
I like Eric Mamet's xml solution best - thanks Eric. it has let me to create this generic sproc that will serialise distinct valus from any column of any table into a comma seperated string
CREATE PROCEDURE usp_distinct_values_to_delimited_string(@table_name NVARCHAR(255), @column_name NVARCHAR(255))
AS
BEGIN
DECLARE @sql NVARCHAR(MAX)
SET @sql = '
SELECT
(
SELECT CAST(t.{column_name} AS NVARCHAR(255)) + '',''
FROM {table_name} t
ORDER BY t.{column_name}
FOR XML PATH('''')
) AS {column_name}_list'
SET @sql = REPLACE(@SQL,'{table_name}',@table_name)
SET @sql = REPLACE(@SQL,'{column_name}',@column_name)
EXEC sp_executesql @sql
END
GO
Enjoy :hehe:
May 5, 2011 at 8:43 am
Thanks
I thought the "political correctness" about correlated sub-query was forgetting how flexible the XML approach was.
Don't repeat it but I still do that sort of things from time to time!!! 😉
Viewing 9 posts - 16 through 23 (of 23 total)
You must be logged in to reply to this topic. Login to reply