sql server - Update in multiples rows -


how can write update when have sub query?

take look:

update people  set name = dbo.formatt_name((select name                               people                               idinstitute = 12))  idinstitute = 12 

i've created function formatt_name(str) returns formatted string.

i update names on table using function, knows how can ?

i error message:

msg 512, level 16, state 1.

i know, 1 result set update. but, have no idea how solve this.

as per comments, have update records of table peoples belongs institute =12 , add condition name not null .

update people set name = dbo.formatt_name(name)    idinstitute=12 , name not null  

edited:

from understanding have format names in each record.

 idinstitute  name     12       antony | jhon | cris | peter    12       kevin| jhon | antony | pcris 

here no need of subquery. find sample function formatted string.

create function [dbo].[formatt_name] (@inputstring varchar(max) ) returns varchar(max) begin declare @index int declare @char char(1) declare @outputstring varchar(255) set @outputstring = lower(@inputstring) set @index = 2 set @outputstring = stuff(@outputstring, 1, 1,upper(substring(@inputstring,1,1))) while @index <= len(@inputstring) begin set @char = substring(@inputstring, @index, 1) if @char in (' ', ';', ':', '!', '?', ',', '.', '_', '-', '/', '&','''','(') if @index + 1 <= len(@inputstring) begin if @char != '''' or upper(substring(@inputstring, @index + 1, 1)) != 's' set @outputstring = stuff(@outputstring, @index + 1, 1,upper(substring(@inputstring, @index + 1, 1))) end set @index = @index + 1 end return isnull(@outputstring,'') end 

and query update,

 update people set name = dbo.formatt_name(name)        idinstitute=12 , name not null  

enter image description here


Comments

Popular posts from this blog

Ansible - ERROR! the field 'hosts' is required but was not set -

customize file_field button ruby on rails -

SoapUI on windows 10 - high DPI/4K scaling issue -