1

Kindly use below code to reflect the error:

CREATE TABLE TESPVTBL
(
    Names   NVARCHAR(20),
    Salary  INT,
    Country NVARCHAR(80)
)

INSERT INTO TESPVTBL (Names, Salary, Country) 
VALUES ('Karthick', 15000, '1300029INDIA'),
       ('BRO1', 15000, '130008INDIA'),
       ('DHARU', 15000, 'US'),
       ('DHARUBRO', 15000, 'US')

SELECT 
    NAMES, 1300029INDIA, 130008INDIA
FROM 
    TESPVTBL
PIVOT
    (SUM(Salary) 
          FOR Country IN (1300029INDIA, 130008INDIA)) AS PT

Is there any way to solve this?

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459

1 Answers1

1

Use square brackets for column names::

SELECT 
    NAMES, [1300029INDIA], [130008INDIA]
FROM 
    TESPVTBL
PIVOT
    (SUM(Salary) 
          FOR Country IN ([1300029INDIA], [130008INDIA])) AS PT

Output:

enter image description here

StepUp
  • 36,391
  • 15
  • 88
  • 148