0
我寫了函數來獲取姓氏,憑據,後綴和中間名。我用名字取代了所有這些,以獲得名字。我將FirstName作爲null放在FirstName中。任何人都可以幫我解決它。任何人都可以幫我找到代碼中的錯誤
alter function FirstName(@Name varchar(100))
returns varchar(25)
as
begin
declare @FirstName varchar(70)
declare @LastName varchar(100)
declare @Suffix varchar(100)
declare @Cred1 varchar(100)
declare @Cred2 varchar(100)
declare @MiddleName varchar(100)
set @LastName = dbo.LastName(@Name)
set @Suffix = dbo.Suffix(@Name)
set @Cred1 = dbo.Cred(@Name)
set @Cred2 = dbo.Cred2(@Name)
set @MiddleName = dbo.MiddleName(@Name)
set @FirstName = @Name
set @FirstName =case when len(@Cred1) >0
then stuff(@FirstName,charindex('%'[email protected]+'%',@Name),len(@Cred1),' ')
else @FirstName
end
set @FirstName =case when len(@Cred2) >0
then stuff(@Name,charindex('%'[email protected]+'%',@Name),len(@Cred2),' ')
else @FirstName
end
set @FirstName =case when len(@Suffix) >0
then stuff(@Name,charindex('%'[email protected]+'%',@Name),len(@Suffix),' ')
else @FirstName
end
set @FirstName =case when len(@LastName) >0
then stuff(@FirstName,charindex('%'[email protected]+'%',@Name),len(@LastName),' ')
else @FirstName
end
set @FirstName =case when len(@MiddleName) >0
then stuff(@Name,charindex('%'[email protected]+'%',@Name),len(@MiddleName),' ')
else @FirstName
end
return @FirstName
end
是的:-)那就是發生了什麼。我無法意識到這一點。 Tanq。 – Shine
請你幫我進一步做一下做下面的任務的想法。 我可以更好地執行上述替換操作嗎?我在做什麼? – Shine