這是在SQL Server中創建一個函數,它接受X和Y列作爲輸入,並返回所需的輸出
create function remove_char(@x_string varchar(500),@y_string varchar(500))
returns varchar(500)
as
begin
declare @Y table(autoid int identity,c char(1))
declare @i int=1;declare @c char(1);
while(LEN(@y_string)>[email protected])
begin
select @c=substring(@y_string,@i,1);
Insert into @Y values(@c)
select @[email protected]+1
end
declare @X table(autoid int identity,c char(1))
set @i=1;
while(LEN(@x_string)>[email protected])
begin
select @c=substring(@x_string,@i,1);
Insert into @X values(@c)
select @[email protected]+1
end
return(select STUFF((select ''+c from @Y
where c in (select c from @X) order by autoid
FOR XML PATH('')),1,0,''))
end
例如
select dbo.remove_char('AMDNO','AMNOXYZ')
你可以使用這個功能來更新您的表
update <table> set y=dbo.remove_char(x,y)
發佈您的查詢嘗試。我們不在這裏做你的工作。 – stefan
@stefan我不知道要使用什麼函數。我發現沒有辦法將varchar轉換爲char數組進行比較。我真的在尋求幫助。至少指導什麼使用。 –
你說的問題的方式只有那些做你的整個工作的人可以提供一個正確的答案。如果你想問你的子問題更通用的問題,它可能會給你更多的選票。我們大多數人都是專業人員,我們不會讓其他程序員免費工作。 – stefan