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.
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 itex: Customer Care------- [Customer Care]ALTER PROCEDURE [dbo].[CustomerQuery_sp] @SpatialIdDynamic AS NVARCHAR(MAX) = null, @SpatialId AS NVARCHAR(MAX) =nullASSET NOCOUNT ONBEGINDECLARE @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 tPIVOT ( 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.vwSpatialReportWHERE Convert(UNIQUEIDENTIFIER,@SpatialId) = SpatialReportIDFOR XML PATH(''), TYPE).value('.', 'NVARCHAR(MAX)') , 1, 1, '');veeranjaneyulu |
|
|
akpaga
Constraint Violating Yak Guru
331 Posts |
Posted - 2013-09-05 : 10:45:50
|
Thank you anjaneya for the reponse but that did not workI want to show the braces in the header of the table but its not doing it . |
|
|
|
|
|
|
|