LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Case when statement gives type mismatch

I am relatively new to this, so maybe I am overlooking something
simple. I am trying to run some queries via VB and can get most of
them to work. However, when I use a Case when statment I get a type
missmatch error. After copying the debug.print to my query analyzer
or directly into Microsoft query, I don't have a problem. It's only
when I run if from VB. Here is my code, if anyone can please help:

stsql = "Set NoCount on " & _
"Select " & _
"CM.Certmainseqno , RefDate = CM.activitydate " & _
"Into #POL from DayOld..Commtrans as CM " & _
"where CM.activitydate = '06/01/04' and CM.commpayee =
'33816230' " & _
"Set NoCount Off " & _
"Select Test = case when RefDate = '06/03/04' then RefDate
else GetDate() end " & _
"From #Pol "
With ActiveSheet.QueryTables.Add(Connection:="ODBC;DSN= Warehouse;Description=DataWarehouse
Summary Database;DATABASE=Warehouse;UseProcForPrepare=0" _
, Destination:=Range("A1"))
.CommandText = Array( _
stsql)
.Name = "GetPols"
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.BackgroundQuery = True
.RefreshStyle = xlInsertDeleteCells
.SavePassword = True
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.PreserveColumnInfo = True
.Refresh BackgroundQuery:=False
End With

Everything works fine if I do not include the case statement. All
records are returned if if have the last piece as select * from #Pol.

Any help would be appreciated.
 
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
Type mismatch Patti[_5_] Excel Programming 3 May 30th 04 02:44 PM
Type mismatch Stuart[_5_] Excel Programming 4 February 19th 04 07:54 PM
Type Mismatch Phil Hageman[_3_] Excel Programming 2 January 9th 04 06:11 PM
Type mismatch while running If statement Stel Excel Programming 4 December 18th 03 09:19 AM


All times are GMT +1. The time now is 12:32 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"