Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default SQL query to ODBC

I'm using the following query to download to Excel
Error says it doesn't expect the keyword Between in the IIf statement.
Works fine without the IIf.
Any suggestions?
vQuery = "SELECT PSPSP100.PARNT, PSPSP100.CSEQN, PSPSP100.PSPCL,
PSPSP100.CHILD, PSPSP100.PSCCL, MSPMP100.PRDNO, MSPMP100.DESCP,
IIf(PSPSP100.PSPCL Between 'AA'And 'YM',MSPMP100.S2APH='C10301A',
MSPMP100.S2APH Like '*') FROM-----"


---
Message posted from http://www.ExcelForum.com/

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 459
Default SQL query to ODBC

Is yours a Jet data source (MS Access, Excel, etc)? The IIF function
is used in Jet to parse text to construct dynamic SQL. IIF uses VBA
expressions and operators.

It looks like you are trying to use IIF to perform a SQL subquery.
This approach simply can't be made to work. The SQL which appears
between the SELECT and FROM keywords should be a list of columns or
literal values. Your IIF function is trying to conditionally add
either

MSPMP100.S2APH='C10301A'

or

MSPMP100.S2APH Like '*'

to the SELECT cause. Such comparisons should appear in the WHERE
clause e.g.

SELECT <column list
FROM <Table list with joins
WHERE <comparisons

It seems you need subqueries to in your WHERE clause. You need to post
more information (DB schema, sample data and exactly what it is you
want to achieve) but, because you should be looking for a pure SQL
solution, you'll have a better chance if you post in the newsgroup
appropriate for your DBMS.

--

gkelle wrote in message ...
I'm using the following query to download to Excel
Error says it doesn't expect the keyword Between in the IIf statement.
Works fine without the IIf.
Any suggestions?
vQuery = "SELECT PSPSP100.PARNT, PSPSP100.CSEQN, PSPSP100.PSPCL,
PSPSP100.CHILD, PSPSP100.PSCCL, MSPMP100.PRDNO, MSPMP100.DESCP,
IIf(PSPSP100.PSPCL Between 'AA'And 'YM',MSPMP100.S2APH='C10301A',
MSPMP100.S2APH Like '*') FROM-----"


---
Message posted from http://www.ExcelForum.com/

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default SQL query to ODBC

Thanks, I'll move it to the where clause and take yur suggestion to post
to an SQL forum


---
Message posted from http://www.ExcelForum.com/

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
ODBC Query Laddie Excel Worksheet Functions 0 April 23rd 10 03:35 PM
ODBC query oddity Arvi Laanemets Excel Discussion (Misc queries) 0 January 12th 09 08:05 AM
ODBC query problem Arvi Laanemets Excel Discussion (Misc queries) 3 September 26th 08 02:03 PM
Using SUM function in MS QUERY with ODBC Francois via OfficeKB.com Excel Discussion (Misc queries) 0 November 29th 07 02:37 PM
ODBC database query gneissgirl Excel Discussion (Misc queries) 0 November 10th 05 06:18 PM


All times are GMT +1. The time now is 06:07 PM.

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

About Us

"It's about Microsoft Excel"