Results 1 to 5 of 5

Thread: SQL problem

  1. #1

    Thread Starter
    New Member
    Join Date
    Mar 2004
    Posts
    9

    SQL problem

    hello everyone,

    does anybpdy know of the equivalent string function of miscrosoft access 2003's "replace" function in its lower versions??

    thanks in advance for any help you can give.

  2. #2
    Don't Panic! Ecniv's Avatar
    Join Date
    Nov 2000
    Location
    Amsterdam...
    Posts
    5,343
    There wasn't one. It had to be coded by you.

    Functions :
    Instr, Left, Mid, Right


    Vince

    BOFH Now, BOFH Past, Information on duplicates

    Feeling like a fly on the inside of a closed window (Thunk!)
    If I post a lot, it is because I am bored at work! ;D Or stuck...
    * Anything I post can be only my opinion. Advice etc is up to you to persue...

  3. #3

    Thread Starter
    New Member
    Join Date
    Mar 2004
    Posts
    9
    Originally posted by Ecniv
    There wasn't one. It had to be coded by you.

    Functions :
    Instr, Left, Mid, Right


    Vince
    is that so?
    anyway thats for the info.
    it's greatly appreciated.

  4. #4
    Addicted Member
    Join Date
    Dec 2001
    Posts
    158
    TempA: Original String
    TempB: The search string ('BLUE') is inside of the TempA text
    TempC: The String to replace the found string with if found (i.e. if "blue' is found, replace 'blue' with 'yellow'.
    TempD: Will contain the new string with 'blue' turned into yellow.


    Code:
    Public Sub Example()
    Dim TempA As String
    Dim TempB As String
    Dim TempC As String
    Dim TempD As String
    
    TempA = "asdfasdfBLUEasdfasd"
    TempB = "BLUE"
    TempC = "YELLOW"
    
    TempD = Replace(TempA, TempB, TempC)
    
    
    '.............  TempD will = "asdfasdYELLOWasdfasd"
    
    End Sub
    '-------------------------------------------------------------------
    
    Public Function Replace(ByVal vntValue As Variant, ByVal strSource As String, ByVal strDest As Variant) As Variant
    'Purpose    Replace part of a string by another.
    'Inputs     vntValue    Value where execute substitution
    '           strSource   String to replace
    '           strDest     String replacement
    
    
    Dim i, j As Integer
    Dim intLngDest As Integer, intLngSource As Integer
    
        If IsNull(vntValue) Then
            Exit Function
        End If
        If strSource <> strDest Then
            intLngDest = Len(strDest)
            If intLngDest = 0 Then
                intLngDest = 1
            End If
            intLngSource = Len(strSource)
        
            i = 1
            j = InStr(i, vntValue, strSource)
            While j <> 0
                vntValue = Left(vntValue, j - 1) & strDest & Right(vntValue, Len(vntValue) - (j + intLngSource - 1))
                i = j + intLngDest
                j = InStr(i, vntValue, strSource)
            Wend
        End If
        Replace = vntValue
    end function

  5. #5

    Thread Starter
    New Member
    Join Date
    Mar 2004
    Posts
    9
    Originally posted by Garratt
    TempA: Original String
    TempB: The search string ('BLUE') is inside of the TempA text
    TempC: The String to replace the found string with if found (i.e. if "blue' is found, replace 'blue' with 'yellow'.
    TempD: Will contain the new string with 'blue' turned into yellow.


    Code:
    Public Sub Example()
    Dim TempA As String
    Dim TempB As String
    Dim TempC As String
    Dim TempD As String
    
    TempA = "asdfasdfBLUEasdfasd"
    TempB = "BLUE"
    TempC = "YELLOW"
    
    TempD = Replace(TempA, TempB, TempC)
    
    
    '.............  TempD will = "asdfasdYELLOWasdfasd"
    
    End Sub
    '-------------------------------------------------------------------
    
    Public Function Replace(ByVal vntValue As Variant, ByVal strSource As String, ByVal strDest As Variant) As Variant
    'Purpose    Replace part of a string by another.
    'Inputs     vntValue    Value where execute substitution
    '           strSource   String to replace
    '           strDest     String replacement
    
    
    Dim i, j As Integer
    Dim intLngDest As Integer, intLngSource As Integer
    
        If IsNull(vntValue) Then
            Exit Function
        End If
        If strSource <> strDest Then
            intLngDest = Len(strDest)
            If intLngDest = 0 Then
                intLngDest = 1
            End If
            intLngSource = Len(strSource)
        
            i = 1
            j = InStr(i, vntValue, strSource)
            While j <> 0
                vntValue = Left(vntValue, j - 1) & strDest & Right(vntValue, Len(vntValue) - (j + intLngSource - 1))
                i = j + intLngDest
                j = InStr(i, vntValue, strSource)
            Wend
        End If
        Replace = vntValue
    end function

    hey thanks for the reply Garratt..but what i really needed is a replace function inside a query statement..

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