Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 16
Default MS database query: Statement CASE WHEN THEN ELSE END

Hi all,

I want to create in Excel (via data/import new external data/new
database query) a query from MS Access database using statement case.
MS query still complains. I tried something like this example (using
Northwind sample database):

SELECT employees.EmployeeID, employees.LastName,
case
when employees.country = 'USA' then 1
else 0
end
FROM Nwind.employees employees


What is wrong? The Microsoft query still complains that it didn't
expect 'employees' after the select column list.

I have also tried several variant like "... code = case ...." or ....
end as 'code'..." but no improvement.


thank you very much for any help.

riso

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 812
Default MS database query: Statement CASE WHEN THEN ELSE END

It fails because your code is not a valid SQL statement.
These are valid SQL statements:

SELECT employees.EmployeeID, employees.LastName, employees.country
FROM employees WHERE employees.country = 'USA';

SELECT Employees.EmployeeID, Employees.LastName, Employees.FirstName,
IIf([Employees]![Country]='USA',1,0) AS Country
FROM Employees;

The latter works in Access and as an SQL statement using ADO or DAO,
but I don't know if it will from Excel in the way you are trying.

Hth,
Merjet


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 16
Default MS database query: Statement CASE WHEN THEN ELSE END

Thank you very much.

I have found that the IIF() work fine.

One thing, I am not able to name columns as I need. Without iif I can
use arbitrary names, but once I use function iif the part of the sql
command "... AS country ..." dissapeared and excel use funny names
expr1001, expr1002 and so on. How to fix it?

I am going to ask this question in separate post.

anyway thank you very much.

riso

On Mar 5, 10:12 pm, "merjet" wrote:
It fails because your code is not a valid SQL statement.
These are valid SQL statements:

SELECT employees.EmployeeID, employees.LastName, employees.country
FROM employees WHERE employees.country = 'USA';

SELECT Employees.EmployeeID, Employees.LastName, Employees.FirstName,
IIf([Employees]![Country]='USA',1,0) AS Country
FROM Employees;

The latter works in Access and as an SQL statement using ADO or DAO,
but I don't know if it will from Excel in the way you are trying.

Hth,
Merjet



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Excel 2003 case sensitive problems with New Database Query havrek Excel Discussion (Misc queries) 1 March 7th 08 05:17 PM
database query not showing foxpro database How I import data mangat New Users to Excel 1 June 24th 07 03:31 PM
Excel query of Postgress database - schema case problem.. Frank Brown Excel Discussion (Misc queries) 0 February 12th 07 09:18 PM
Anyone Else Use Database Query to Query Another Sheet in the Same Excel Workbook? jocke Excel Discussion (Misc queries) 1 November 29th 05 01:44 PM
Anyone Else Use Database Query to Query Another Sheet in the Same Excel Workbook? jocke Excel Discussion (Misc queries) 0 November 28th 05 06:37 PM


All times are GMT +1. The time now is 11:56 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"