SQL Server 2008 Updating VarChar Column with a UDF?

馋奶兔 提交于 2019-12-12 17:25:50

问题


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.


回答1:


UPDATE mytable
    SET mycolumn = dbo.myfunc('abc', mycolumn)


来源:https://stackoverflow.com/questions/8406300/sql-server-2008-updating-varchar-column-with-a-udf

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!