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 CASE statement on EXCEL VBA

Hello folks ! How can I use CASE WHEN statement on excel vba ? I'm using
excel sheet like database I did :

dim db as dao.database
dim rs as dao.recordset
dim cSQL as string

set db=opendatabase(thisworkbook.path & "\" &
thisworkbook.name,false,false,"Excel 8.0")

cSQL="select cd_codigo, (case when cd_hist=1 then valor else 0 end), (case
when cd_hist=2 then valor else 0 end) from [Plan1$]"

set rs=db.openrecordset(cSQL)

but this code make a error. Why ?

regards.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 37
Default SQL CASE statement on EXCEL VBA

My understanding is that the CASE statement is supported for SQL Server
T-SQL. DAO, of which the OpenDatabase method is a part, is developed for
JET workspaces as well as ODBCDirect workspaces. The default for DAO is a
connection to a JET datasource. JET SQL syntax does not support the CASE
SQL statement. One alternative would be to use an IIF statement instead.
For example:

IIF(cd_hist=1, valor, 0)

--
David Lloyd
MCSD .NET
http://LemingtonConsulting.com

This response is supplied "as is" without any representations or warranties.


"Gilson" wrote in message
...
Hello folks ! How can I use CASE WHEN statement on excel vba ? I'm using
excel sheet like database I did :

dim db as dao.database
dim rs as dao.recordset
dim cSQL as string

set db=opendatabase(thisworkbook.path & "\" &
thisworkbook.name,false,false,"Excel 8.0")

cSQL="select cd_codigo, (case when cd_hist=1 then valor else 0 end), (case
when cd_hist=2 then valor else 0 end) from [Plan1$]"

set rs=db.openrecordset(cSQL)

but this code make a error. Why ?

regards.


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
Case Statement jlclyde Excel Discussion (Misc queries) 3 December 4th 08 05:04 PM
CASE statement equivalent Beema Excel Worksheet Functions 1 December 15th 04 09:32 AM
Case Statement error David Adamson[_3_] Excel Programming 2 June 23rd 04 05:01 AM
Case Statement Help stck2mlon Excel Programming 3 June 2nd 04 01:44 PM
Case statement smi Excel Programming 2 October 18th 03 02:20 PM


All times are GMT +1. The time now is 10:17 AM.

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"