Results 1 to 4 of 4

Thread: [RESOLVED] .csv file select statement problem

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Aug 2009
    Location
    Los Angeles
    Posts
    1,335

    Resolved [RESOLVED] .csv file select statement problem

    This is similiar to the other problem I have posted , althought I think I have narrowed this one down a bit more.

    It seems that if I use this statement and some of my Street Full Address fields do not have a "-" then I get an error, "Provider could not determine the string value"

    If I remove the Left and InStr then I am good to go

    So I examined one of my database files and discovered that in one of them there were some records of address with no postal code "-" ,I deleted them and it works


    Command Code:
    1. Dim comm As New OleDb.OleDbCommand("Select *, Left(([Street Full Address]), InStr([Street Full Address],'-')-1)  as StreetFullAddress From " & Me.OpenFileDialog1.SafeFileName & " Where Status  <> 'S'", con)
    2.         Dim dalist As New OleDbDataAdapter(comm)

    In summary I think what I need is to account for there maybe being records that dont have the "-" in the address?

  2. #2
    PowerPoster
    Join Date
    Oct 2002
    Location
    British Columbia
    Posts
    9,758

    Re: .csv file select statement problem

    You need to ensure the Instr function returns a valid value to be used by the Left function. If Instr returns 0(ie, no '-' in the address) you are passing -1 to the Left function, which is obviously invalid.

    MS Access has the IIF function, basically an If statement within a SQL statement.

    Code:
    Select *, 
    Left([Street Full Address], IIF(InStr([Street Full Address],'-')>0, InStr([Street Full Address],'-')-1, Len([Street Full Address]))) as StreetFullAddress
    From

  3. #3

    Thread Starter
    Frenzied Member
    Join Date
    Aug 2009
    Location
    Los Angeles
    Posts
    1,335

    Re: .csv file select statement problem

    Quote Originally Posted by brucevde View Post
    You need to ensure the Instr function returns a valid value to be used by the Left function. If Instr returns 0(ie, no '-' in the address) you are passing -1 to the Left function, which is obviously invalid.

    MS Access has the IIF function, basically an If statement within a SQL statement.

    Code:
    Select *, 
    Left([Street Full Address], IIF(InStr([Street Full Address],'-')>0, InStr([Street Full Address],'-')-1, Len([Street Full Address]))) as StreetFullAddress
    From
    Thank you, thats exactly what I was looking for, I was struggling on how to write it.

    I now have a situation where there is a "-" after the numbers in the address, so with this new statement iI lose the street name.

    example: Data normally comes as

    1313 Mockingbird lane, MyCity, CA 91302-0045

    sometimes there is no "-0045"

    now I discovered there is a record that has

    1313-Mockigbird lane, MyCity, CA 91302-0045


    I cant see a way to account for this?? Can you?

    Thanks again for your help

  4. #4

    Thread Starter
    Frenzied Member
    Join Date
    Aug 2009
    Location
    Los Angeles
    Posts
    1,335

    Re: .csv file select statement problem

    vb Code:
    1. Dim comm As New OleDb.OleDbCommand("Select *, Left([Street Full Address], IIF(InStr(7,[Street Full Address],'-')>0, InStr(7,[Street Full Address],'-')-1, Len([Street Full Address])))  as StreetFullAddress From " & Me.OpenFileDialog1.SafeFileName & " Where Status  <> 'S'", con)
    2.         Dim dalist As New OleDbDataAdapter(comm)

    Did the trick, so far

    Thanks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width