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 2008 Forums
 Transact-SQL (2008)
 wrapping braces for field values

Author  Topic 

akpaga
Constraint Violating Yak Guru

331 Posts

Posted - 2013-09-04 : 16:06:33
hi friends below is the stored procedure I use to Pivot the column values as table headers. But my problem is i want to wrap the column values of Analysis Description field which are showing up as table headers with brace [] at the start and end of the string....How can i achieve it

ex: Customer Care------- [Customer Care]


ALTER PROCEDURE [dbo].[CustomerQuery_sp]
@SpatialIdDynamic AS NVARCHAR(MAX) = null,
@SpatialId AS NVARCHAR(MAX) =null
AS
SET NOCOUNT ON
BEGIN
DECLARE @cols AS NVARCHAR(MAX);
DECLARE @query AS NVARCHAR(MAX);

select @cols = STUFF((SELECT distinct ',' +
QUOTENAME(AnalysisDescription)
FROM Customer.vwSpatialReport
where Convert(uniqueidentifier,@SpatialId) = SpatialReportID
FOR XML PATH(''), TYPE
).value('.', 'NVARCHAR(MAX)')
, 1, 1, '');

SELECT @query =

'SELECT *
FROM
(
SELECT
SpatialReportID,
AnalysisDescription,
ResultDescription
FROM Custeomer.vwSpatialReport
WHERE Convert(uniqueidentifier,'''+@SpatialIdDynamic +''') = SpatialReportID

) AS t
PIVOT
(
MAX(ResultDescription)
FOR AnalysisDescription IN( ' + @cols + ' )' +
' ) AS p ; ';

execute(@query);
end

VeeranjaneyuluAnnapureddy
Posting Yak Master

169 Posts

Posted - 2013-09-05 : 01:44:52
Replace The Code And Run,

SELECT @cols = STUFF((SELECT DISTINCT ',[' +
QUOTENAME(AnalysisDescription) + ']'
FROM Customer.vwSpatialReport
WHERE Convert(UNIQUEIDENTIFIER,@SpatialId) = SpatialReportID
FOR XML PATH(''), TYPE
).value('.', 'NVARCHAR(MAX)')
, 1, 1, '');


veeranjaneyulu
Go to Top of Page

akpaga
Constraint Violating Yak Guru

331 Posts

Posted - 2013-09-05 : 10:45:50
Thank you anjaneya for the reponse but that did not work

I want to show the braces in the header of the table but its not doing it .

Go to Top of Page
   

- Advertisement -