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

Our new SQL Server Forums are live! Come on over! We've restricted the ability to create new threads on these forums.

SQL Server Forums
Profile | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 wrapping braces for field values
 Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

akpaga
Constraint Violating Yak Guru

USA
331 Posts

Posted - 09/04/2013 :  16:06:33  Show Profile  Reply with Quote
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

India
169 Posts

Posted - 09/05/2013 :  01:44:52  Show Profile  Reply with Quote
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

USA
331 Posts

Posted - 09/05/2013 :  10:45:50  Show Profile  Reply with Quote
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 .


Edited by - akpaga on 09/05/2013 12:11:15
Go to Top of Page
  Previous Topic Topic Next Topic  
 Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.12 seconds. Powered By: Snitz Forums 2000