2

I have a scalar function that takes a two variables @input1 @input2 and it returns the value of @input1 and @input2 (actual thing is more complex but this distills the idea).

I want to update all rows in a table column using this function, passing the value 'abc ' for @input1 and using the column name in @input2, so my update statement would look something like:

update mytable set mycolumn = (select dbo.myfunc( 'abc ' , mycolumn ) )
-- prepend the literal 'abc ' to every row for column mycolumn

But this is of course not allowed.

I'm trying to perform some mass string handling on a couple of columns based on some string rules. All ideas appreciated.

Thanks.

Snowy
  • 5,942
  • 19
  • 65
  • 119
  • What makes you think the syntax in your question isn't allowed? It should work fine though Joe's answer is simpler. – Martin Smith Dec 06 '11 at 22:10

1 Answers1

4
UPDATE mytable
    SET mycolumn = dbo.myfunc('abc', mycolumn)
Joe Stefanelli
  • 132,803
  • 19
  • 237
  • 235