Possible Duplicate:
Concatenate many rows into a single text string?
Suppose I have table named tblContractMail
. Sample table with data given below:
I need to write a SQL query that produces the following output:
'abc@akij.net;efg@akij.net;hjk@akij.net'
I know two possibilities:
DECLARE @str varchar(4000)
SELECT @str = COALESCE(@str + ';', '') + strContract FROM tblContractMail
SELECT @str
and:
DECLARE @str varchar(4000)
SET @str = (SELECT strContract + ';' FROM tblContractMail FOR XML PATH(''))
SET @str = SUBSTRING(@str, 1, LEN(@str)-1)
SELECT @str
Is there any way to get this output in a single query (I mean with out declaring any variables)?