Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 for xml path returns varchar(max) ?

Author  Topic 

yns.emre
Starting Member

11 Posts

Posted - 2010-04-15 : 08:31:12
SELECT K.KimlikKey,STUFF((SELECT ',' + TEL.TelNo
FROM TEL
WHERE TEL.KimlikKey = dbo.K.KimlikKey FOR XML PATH('')) , 1, 1, '') AS Telefon FROM KIMLIK K

how can i change return type varchar(max) to varchar(50) ?

Transact Charlie
Master Smack Fu Yak Hacker

3451 Posts

Posted - 2010-04-15 : 08:55:59
Use CAST or CONVERT


Charlie
===============================================================
Msg 3903, Level 16, State 1, Line 1736
The ROLLBACK TRANSACTION request has no corresponding BEGIN TRANSACTION
Go to Top of Page

yns.emre
Starting Member

11 Posts

Posted - 2010-04-15 : 08:59:32
i know using cast and convert but how ? i set Convert(varchar(50),',' + TEL.TelNo) but i does not effect,also this is a view.
Go to Top of Page

Transact Charlie
Master Smack Fu Yak Hacker

3451 Posts

Posted - 2010-04-15 : 09:11:44
Derived table?

SELECT
r.KimLikKey
, CAST(r.Telefon AS VARCHAR(50))
FROM
(
SELECT
K.KimlikKey AS KimLikKey
, STUFF(
(
SELECT ',' + TEL.TelNo
FROM TEL
WHERE TEL.KimlikKey = dbo.K.KimlikKey
FOR XML PATH(''))

, 1
, 1
, '') AS Telefon
FROM
KIMLIK K
)
AS r



Charlie
===============================================================
Msg 3903, Level 16, State 1, Line 1736
The ROLLBACK TRANSACTION request has no corresponding BEGIN TRANSACTION
Go to Top of Page
   

- Advertisement -