Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Multiple replace in expression

Author  Topic 

The Enigma
Posting Yak Master

179 Posts

Posted - 2007-08-16 : 21:25:20
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





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




Enigma

The Enigma
Posting Yak Master

179 Posts

Posted - 2007-08-16 : 22:21:19
BTW .. figured it out with a little help from Pat Phelan ...
Go to Top of Page
   

- Advertisement -