Results 1 to 5 of 5
  1. #1
    Join Date
    Jul 2003
    Location
    The Dark Planet
    Posts
    1,401

    Unanswered: Multiple replace in expression

    Guys ... got a puzzle kinda problem am stuck up with so asking for your help (after all .. you are the gurus)... What i need to do is append Src. to any column name that comes in the expression.


    Here we go ... and the last query is part of what I was coming up with ... not exactly working
    Code:
     
    CreateTable ColumnNames
    (
    ColumnName varchar(256)
    )
    go
    Insertinto ColumnNames
    Select'name'
    UNION
    Select'dbid'
    UNION
    Select'sid'
    UNION
    Select'mode'
    UNION
    Select'status'
    UNION
    Select'status2'
    UNION
    Select'crdate'
    UNION
    Select'reserved'
    UNION
    Select'category'
    UNION
    Select'cmptlevel'
    UNION
    Select'filename'
    UNION
    Select'version'
    go
    Declare @Expression varchar(256)
    Select @Expression ='dbid = 1 AND cmptlevel = 100'
     
    Selectreplace(@Expression,ColumnName,'Src.'+ColumnName)from ColumnNames Wherecharindex('Src.',replace(@Expression,ColumnName,'Src.'+ColumnName))<> 0

    Get yourself a copy of the The Holy Book

    order has no physical Brett in The meaning of a Kaiser . -database data

  2. #2
    Join Date
    Feb 2004
    Location
    In front of the computer
    Posts
    15,579
    Provided Answers: 54
    Something like:
    Code:
    SELECT @c =
       CASE WHEN @c IS NULL THEN '' ELSE @c + ', ' END
    +  CASE WHEN ColumnName LIKE 'src.' THEN ColumnName ELSE 'src.' + ColumnName END
       FROM ColumnNames
    -PatP

  3. #3
    Join Date
    Jul 2003
    Location
    The Dark Planet
    Posts
    1,401
    Pat .. thanks for the suggestion .. but i dont see how it would work. I have an expression where i need to append "src." to any column name that appears in the expression.
    Get yourself a copy of the The Holy Book

    order has no physical Brett in The meaning of a Kaiser . -database data

  4. #4
    Join Date
    Jul 2003
    Location
    The Dark Planet
    Posts
    1,401
    Thanks ... that did work

    Declare @Expression varchar(256)
    Select @Expression ='dbid = 1 AND crdate = datediff(mm,getdate,6)'
    Select @Expression =replace(@Expression,ColumnName,'Src.'+ColumnName)from ColumnNames Wherecharindex('Src.',replace(@Expression,ColumnName,'Src.'+ColumnName))<> 0
    Select @Expression
    Get yourself a copy of the The Holy Book

    order has no physical Brett in The meaning of a Kaiser . -database data

  5. #5
    Join Date
    May 2005
    Location
    South Africa
    Posts
    1,365
    Provided Answers: 1
    You don't need the where clause

Posting Permissions

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