ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   SQL: custom names of columns when using IIF (excel quering access database) (https://www.excelbanter.com/excel-programming/384571-sql-custom-names-columns-when-using-iif-excel-quering-access-database.html)

riso

SQL: custom names of columns when using IIF (excel quering access database)
 
Hi all,

I am creating in Excel (via data/import new external data/new
database query) a query from MS Access database using statement IIF,
but excel ignore my column names (... AS 'custom name'...) and use
artificial ones (e.g. expr1002,expr1003 etc)

My code looks like:

SELECT table1.persID AS 'ID personal',
table1.surname+' '+table1.name AS 'Full name' ,
IIF ((select top 1 tbl2.order from tbl2 tbl2
where table1.year_ID = tbl2.year_ID and
tbl2.PID = table1.PID and
tbl2.order is not null
)is null
, null
, (select top 1 tbl2.order from tbl2 tbl2
where table1.year_ID = tbl2.year_ID and
tbl2.PID = table1.PID and
tbl2.order is not null)
) as 'Order'
FROM table1 table1

I want to have table with columns 'ID personal', 'Full name' and
'Order', but I recieve fine data with funny column names. What is
wrong?

Thank you for any hint.

riso


merjet

SQL: custom names of columns when using IIF (excel quering access database)
 
Not knowing your tables, I can't help much. But one thing -- use
brackets rather than quotes to enclose field names with spaces, e.g.
AS [ID personal]

Hth,
Merjet




All times are GMT +1. The time now is 05:03 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com