Q:

SQL Server with non-alphabetic value as column name

I am building a pivot query inside a CTE. I have a table Table_1:
Store      Count     xCount
-------    ----     ------
101        1        138
109        1        59
101        2        282
109        2        97
105        3        60
109        3        87
105        4.a      60
109        4.b      87

In Table_1, datatype of column count is varchar(10).
I used dynamic pivot query to pivot Table_1 
DECLARE @DynamicCol AS NVARCHAR(MAX),
        @SQL  AS NVARCHAR(MAX)

select @DynamicCol = STUFF((SELECT distinct ',' + QUOTENAME(count) 
                    from table_1
                    FOR XML PATH(''), TYPE
                    ).value('.', 'NVARCHAR(MAX)') 
                    ,1,1,'')

set @SQL = ';WITH CTE as (
            SELECT store,' + @DynamicCol + ' from 
             (
               select * from table_1
            ) res
            pivot 
            (
               MAX(xCount)
                for Count in (' + @DynamicCol + ')
            ) piv ) SELECT * 
FROM CTE where 4.a is null'

execute(@SQL);

and get result as :
| STORE |   1 |   2 |   3 | 4.a |
+-------+-----+-----+-----+-----+
|   101 | 138 | 282 | null| null|
|   105 | null| null|  60 | 60  |
|   109 |  59 |  97 |  87 | 87  |

Now, I tried to get data from column 3 and 4.a where 3 and 4.a is null.
The query I build to get data is
 Select * from CTE where 3 is null
 Select * from CTE where 4.a is null

Also i tried to use this inside case statement as :
Select *,case when (3 is null) then 'some result' else '' end from CTE 

In every query I am not getting any value returned by queries. 
I tried by to append 'X' in each pivoted column and remove '.' from column anme, like column name looks like
| STORE |  X1 |  X2 |  X3 | X4a |
+-------+-----+-----+-----+-----+
|   101 | 138 | 282 | null| null|
|   105 | null| null|  60 | 60  |
|   109 |  59 |  97 |  87 | 87  |

I am not able to query for this. Could anyone help me or suggest me any other idea to get data using above mentioned query ?

A:

You have to wrap identifier that starts with digit with []:
DECLARE @DynamicCol AS NVARCHAR(MAX),
        @SQL  AS NVARCHAR(MAX)

select @DynamicCol = STUFF((SELECT distinct ',' + QUOTENAME(count) 
                    from table_1
                    FOR XML PATH(''), TYPE
                    ).value('.', 'NVARCHAR(MAX)') 
                    ,1,1,'')

set @SQL = ';WITH CTE as (
            SELECT store,' + @DynamicCol + ' from 
             (
               select * from table_1
            ) res
            pivot 
            (
               MAX(xCount)
                for Count in (' + @DynamicCol + ')
            ) piv ) SELECT * 
FROM CTE where [4.a] is null'  -- here

execute(@SQL);

