I am trying to pivot a resultset, one of the values in the rows which iam comparing against is COutputData_2_Magnesium Stearate [%]. SQL does not seem to like the [%] symbol, i dont have anyway to change the how the name is shown in the result set. Is there a way I can escape [%] when pivoting. Thanks.
You should use the QUOTENAME
function to get the proper escaping for possible non standard identifiers.
SELECT QUOTENAME('COutputData_2_Magnesium Stearate [%]')
returns
[COutputData_2_Magnesium Stearate [%]]]
So use that.
Example
WITH T(Id, Val)
AS (SELECT 1, 'COutputData_2_Magnesium Stearate [%]')
SELECT *
FROM T PIVOT ( AVG(Id) FOR Val IN ([COutputData_2_Magnesium Stearate [%]]]) ) AS P;
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.