Calculated column in wrong position when using `SELECT *`

旧街凉风 提交于 2019-12-08 04:11:15

From the investigations you've already done, it looks like you're stuffed.

You may have to reference the record set's column's by name rather than position.

Change your select statement to:

  Sql = _
       "SELECT Orders.*, " & vbCr & _
       "       IIF(TRUE, 55, -99) AS calculated_col" & vbCr & _
       "  FROM Orders;" 

By declaring the table name, I think it prevents having to determine what is the default table.

The SQL code in the question is proscribed by the SQL standard: when * is used without dot-qualification (and disregarding the special case COUNT(*)) then no other columns may appear.

This gives a clue to the solution: dot-qualify the * !!

e.g. this works as expected, with calculated_column appearing as the rightmost column in the result:

SELECT Orders.*, 
       IIF(TRUE, 1, 0) AS calculated_col
  FROM Orders;
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!