|
|
|
|
||||||
![]() |
|
|
LinkBack | Outils de la discussion |
|
|
#1 |
|
Messages: n/a
Hébergeur: |
HI All,
For my application, I need to show previous changes (like who change it, their comments,changedate etc.) for the particular record . For that purpose, i need to Concatenating Row Values into single variable. I created 1 udf for this but it's not giving correct results. It's always giving last row data. What is the best approach to Concatenate Row Values into single variable? Any kind of is greatly appreciated. Here is my query declare @PreviousComments nvarchar(max) select @PreviousComments = '' SELECT @PreviousComments = COALESCE(@PreviousComments , '') + '<NOBR> ' + dbo.tbl_APP_USERS.FULL_NAME + ' ' + ' ' + ' ' + convert(varchar(15),dbo.tbl_RESOURCE_REQUEST_DETAI LS_HISTORY.UPD_DATE,101) + ' ' + dbo.tbl_RESOURCE_REQUESTDETAIL_STATUS.STATUS_NAME + ' </NOBR> <br /> ' + isnull(dbo.tbl_RESOURCE_REQUEST_DETAILS_HISTORY.CO MMENTS,'') + '<br />' FROM dbo.tbl_RESOURCE_REQUEST_DETAILS_HISTORY INNER JOIN dbo.tbl_RESOURCE_REQUESTDETAIL_STATUS ON dbo.tbl_RESOURCE_REQUEST_DETAILS_HISTORY.REQUESTDE TAIL_STATUS = dbo.tbl_RESOURCE_REQUESTDETAIL_STATUS.STATUS_ID INNER JOIN dbo.tbl_APP_USERS on dbo.tbl_APP_USERS.tbl_APP_User_ID = dbo.tbl_RESOURCE_REQUEST_DETAILS_HISTORY.UPD_USER_ ID where tbl_RESOURCE_REQUEST_DETAILS_HISTORY.RequestDetail _ID = 100145 order by tbl_RESOURCE_REQUEST_DETAILS_HISTORY.UPD_DATE DESC select @PreviousComments Regards Anil |
|
|
|
#2 |
|
Messages: n/a
Hébergeur: |
Here are a few methods:
http://www.projectdmx.com/tsql/rowconcatenate.aspx If you are on SQL Server 2005/2008, then the FOR XML PATH method will be best. -- Plamen Ratchev http://www.SQLStudio.com |
|
![]() |
| Outils de la discussion | |
|
|