I have a query as :
SELECT 'Item' AS TypeID,
iORCompID AS iEntityID,
iORCompID AS iParentEntityID,
'' as Source,
vComments as Comment
FROM
OrderResultComponents
WHERE IOrderID = @IEntityID
The data i get is following
TypeID | iEntityID | iParentEntityID | Source | Comment
Item | 1045 | 1045 | | Item Found some pending comments \X000d\ by UserID1
Item | 1027 | 1027 | | Item Found with some pending comments \X000d\ by UserID2
Item | 5389 | 5389 | | Item Found with \X000d\ some \X000d\ pending comments \X000d\ by UserID1
(\X000d\ is Char(13) i guess)
However i want data to be like :
TypeID | iEntityID | iParentEntityID | Source | Comment
Item | 1045 | 1045 | | Item Found some pending comments
Item | 1045 | 1045 | | by UserID1
Item | 1027 | 1027 | | Item Found with some pending comments
Item | 1027 | 1027 | | by UserID2
Item | 5389 | 5389 | | Item Found with
Item | 5389 | 5389 | | some
Item | 5389 | 5389 | | pending comments
Item | 5389 | 5389 | | by UserID1
i.e. I want to split my Comment field with next line character of DB and repeat the other fields with this split...Any help???
EDIT: Ah, I got a hint from Split one column into multiple rows
Please correct my query if its not valid.
SELECT
'Item' AS TypeID, '' as SetID,T.iORCompID , RIGHT(LEFT(T.vComments,Number-1),
CHARINDEX(char(13),REVERSE(LEFT(char(13)+T.vComments,Number-1))))
FROM master..spt_values, OrderResultComponents T
WHERE Type = 'P'
AND Number BETWEEN 1
AND LEN(T.vComments)+1
AND (SUBSTRING(T.vComments,Number,1) = char(13) ) AND T.IOrderID = @iEntityID