Re: Concat tables into one row in view



M@ (mattcushing@xxxxxxxxx) writes:
found a really good alternative on sqlteam.com

USE Northwind
GO
CREATE FUNCTION dbo.ConcatOrderProducts(@OrderID int)
RETURNS VARCHAR(8000)
AS
BEGIN
DECLARE @Output VARCHAR(8000)
SELECT @Output = COALESCE(@Output+', ', '') + CONVERT(varchar(20),
P.ProductName)

Beware! The correct result of this operation is not defined! You may get
what you want, you may get something else! It works most of the time,
but there is no guarantee!




--
Erland Sommarskog, SQL Server MVP, esquel@xxxxxxxxxxxxx

Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/prodtechnol/sql/2005/downloads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodinfo/previousversions/books.mspx
.



Relevant Pages

  • Re: 14 byte date/time in file name
    ... DECLARE @x VARCHAR; ... guy who had written the same code six times, rather than writing a loop. ... Erland Sommarskog, SQL Server MVP, esquel@xxxxxxxxxxxxx ... Books Online for SQL Server 2005 at ...
    (microsoft.public.sqlserver.programming)
  • Re: Grouping by Day for a Date Range
    ... an item goes in an out of a workflow state. ... DECLARE @YESTERDAY DATETIME; ... Erland Sommarskog, SQL Server MVP, esquel@xxxxxxxxxxxxx ... Books Online for SQL Server 2005 at ...
    (comp.databases.ms-sqlserver)
  • Re: Select several values into a single variable
    ... declare @bal money ... declare @addition money ... both SQL Server 2000 and 2005 at the moment. ... Books Online for SQL Server 2005 at ...
    (comp.databases.ms-sqlserver)
  • Re: Transposing rows to columns
    ... CREATE FUNCTION dbo.ConcatOrderProducts(@OrderID int) ... DECLARE @Output VARCHAR ... Erland Sommarskog, SQL Server MVP, esquel@xxxxxxxxxxxxx ... Books Online for SQL Server 2005 at ...
    (comp.databases.ms-sqlserver)
  • [NT] Microsoft SQL Server 2000 OpenDataSource Buffer Overflow
    ... Microsoft's database server SQL Server 2000 has a remotely exploitable ... Please see the "Fix Information" section for more details. ... attacker in an exploit of the overflow will run uninhibited. ... declare @saved_return_address nvarchar ...
    (Securiteam)