Weird IIF problem

NaderC

Registered User.
Local time
Today, 06:13
Joined
Aug 22, 2007
Messages
10
Hi, I have a table with two fields: CustomerName and OrderNumber.
Some order numbers have dashes, for example:
123-4, 123-5, 123-6 etc.
I wrote a query to strip those dashes from these ordernumbers, but only for 3 specific customers: Mark, Mike and Jane.
This is the query:
Code:
SELECT CustomerName, OrderNumber, 
    IIf(InStr(1,[OrderNumber],"-")<>0 And InStr(1,[OrderNumber],"-B")=0,
        IIf([CustomerName] Like '*mark*' Or [CustomerName] Like '*mike*' Or [CustomerName] Like '*jane*',
            CStr(Mid([OrderNumber],1,InStr(1,[OrderNumber],"-")-1)),
        CStr([OrderNumber])),
    CStr([OrderNumber])) AS NewOrderNumber
FROM Test
GROUP BY CustomerName, OrderNumber, 
IIf(InStr(1,[OrderNumber],"-")<>0 And InStr(1,[OrderNumber],"-B")=0,
        IIf([CustomerName] Like '*mark*' Or [CustomerName] Like '*mike*' Or [CustomerName] Like '*jane*',
            CStr(Mid([OrderNumber],1,InStr(1,[OrderNumber],"-")-1)),
        CStr([OrderNumber])),
    CStr([OrderNumber]));

This query works great when I run it from Access. However, if I run it from Visual Basic .NET, it does not strip any dashes for any customers. I am using the following connection string:
Provider=Microsoft.Jet.OLEDB.4.0;Data Source = C:\test.mdb
And the following query:
SELECT * FROM [Strip] ORDER BY NewOrderNumber
(Strip is the query name in Access)

Did anyone encounter a problem like this before?

Thank you,

Nader
 
hmmm, if I were to try and run that in VB, I would have to replace all of the double quotes (") with single quotes (') and get rid of all the brackets in favor of this convention Table_Name.Column_Name

Not sure if VB .NET will be the same but you might try it...
 
Solved

I found out that the problem was using LIKE keywords inside IIF statements. I used equal signs instead and it worked.
 

Users who are viewing this thread

Back
Top Bottom