I am using an update query as follows:
UPDATE PeopleTable
SET firstname = CAST(REPLACE(CAST(firstname as nvarchar(max)), 'John', 'ReplacedFirstName') as ntext)
I would like to do the same for several first names like "Dave, Tom, Harry, Rick, Nick"
How do I do this correctly?
I tried something like this:
create procedure proc2
@sp varchar(25)
as
select UPDATE PeopleTable SET first name = CAST(REPLACE(CAST(BODY as
nvarchar(max)), searchString = @sp,'ReplacedFirstName') as ntext)
go
declare @sp varchar(25)
//I want to loop here and execute the stored proc for a list of names
set @sp = 'name'
exec proc2 @sp
PreparedStatement pstmt = null;
String query = "UPDATE PeopleTable SET firstname = CAST(REPLACE(CAST(firstname as nvarchar(max)), ? ,'ReplacedFirstName') as ntext)";
pstmt = conn.prepareStatement(query);
for(String s: myList) {
pstmt.setString(1, s);
pstmt.addBatch();
}
pstmt.executeUpdate();