Question : Incorrect Syntax creating SGL alias column name

I am trying to build a query with alias column names in my ASP.NET application to query the sql database.  These alias names will be used to query out data for display on the website.  I am using CASE but am getting an error:  {"Incorrect syntax near 'A_Flag'."}

I was using AS but had the same error.  What is the correct syntax for setting multiple alias names?

Here is my query:


strSQL = "SELECT DISTINCT PIN,  Form, Status_Flag, CASE Status_Flag " +
                      " WHEN 'A' THEN 1 ELSE 0  'A_Flag' " +
                      " WHEN 'Q' THEN 1 ELSE 0  'Q_Flag' " +
                      " WHEN 'W' THEN 1 ELSE 0  'W_Flag' " +
                      " WHEN 'O' THEN 1 ELSE 0  'O_Flag' " +
                      " WHEN 'D' THEN 1 ELSE 0  'D_Flag' " +
                      " WHEN 'Z' THEN 1 ELSE 0  'Z_Flag' " +
                      " WHEN 'X' THEN 1 ELSE 0  'X_Flag' " +
                      " WHEN 'U' THEN 1 ELSE 0  'U_Flag' " +
                      " FROM t_Answer GROUP BY RecNum, " +
                      " Form, PIN, Status_Flag, A_Flag, L_Flag, Q_Flag, W_Flag, O_Flag, D_Flag," +
                      " Z_Flag, X_Flag, U_Flag;";

ptslv

Answer : Incorrect Syntax creating SGL alias column name

this should work better:
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
strSQL = "SELECT PIN,  Form, Status_Flag " + 
                      " ,CASE Status_Flag WHEN 'A' THEN 1 ELSE 0 END  [A_Flag] " +
                      " ,CASE Status_Flag WHEN 'Q' THEN 1 ELSE 0 END  [Q_Flag] " +
                      " ,CASE Status_Flag WHEN 'W' THEN 1 ELSE 0 END  [W_Flag] " +
                      " ,CASE Status_Flag WHEN 'O' THEN 1 ELSE 0 END  [O_Flag] " +
                      " ,CASE Status_Flag WHEN 'D' THEN 1 ELSE 0 END  [D_Flag] " +
                      " ,CASE Status_Flag WHEN 'Z' THEN 1 ELSE 0 END  [Z_Flag] " +
                      " ,CASE Status_Flag WHEN 'X' THEN 1 ELSE 0 END  [X_Flag] " +
                      " ,CASE Status_Flag WHEN 'U' THEN 1 ELSE 0 END  [U_Flag] " +
                      " FROM t_Answer GROUP BY RecNum, Form, PIN, Status_Flag " +
                      " ,CASE Status_Flag WHEN 'A' THEN 1 ELSE 0 END  " +
                      " ,CASE Status_Flag WHEN 'Q' THEN 1 ELSE 0 END  " +
                      " ,CASE Status_Flag WHEN 'W' THEN 1 ELSE 0 END  " +
                      " ,CASE Status_Flag WHEN 'O' THEN 1 ELSE 0 END  " +
                      " ,CASE Status_Flag WHEN 'D' THEN 1 ELSE 0 END  " +
                      " ,CASE Status_Flag WHEN 'Z' THEN 1 ELSE 0 END  " +
                      " ,CASE Status_Flag WHEN 'X' THEN 1 ELSE 0 END  " +
                      " ,CASE Status_Flag WHEN 'U' THEN 1 ELSE 0 END  " +
                      " ";
Random Solutions  
 
programming4us programming4us