içinde bir tablo değişkeni bildirmek ve bu benim tek outcomes
tablodur:Ben örnek bir sorgu üzerinde çalışıyorum bir kullanıcı tanımlı işlevin
**ship**
Bismarck
California
California
Duke of York
Fuso
Hood
King George V
Kirishima
Prince of Wales
Rodney
Schamhorst
South Dakota
Tennessee
Washington
West Virginia
Yamashiro
ben ilk ve son boşluklar arasındaki karakterleri değiştirmek üzerinde çalışıyorum *
ile dizelerde. Ve doğrudur aşağıdaki kodu, var: kodunun çalıştığını ama çok zorlanmadan yeniden kullanabilirsiniz böylece kullanıcı tanımlı işlevi içinde bir tablo değişkeni yapmak istiyorum
select
left(ship, charindex(' ', ship) - 1) + ' ' +
replicate('*', charindex(' ', substring(ship, charindex(' ', ship) + 1, len(ship))) + 1 -2) + ' ' +
reverse(left(reverse(ship), charindex(' ', reverse(ship)) - 1))
from outcomes
where charindex(' ', substring(ship, charindex(' ', ship) + 1, len(ship))) > 1;
. Kod Aşağıdaki tablo olarak değişkendir bildirmek için kullanılır ve doğru:
declare @ship_outcome table
( final_work nvarchar(30)
)
insert into @ship_outcome (final_work)
select
left(ship, charindex(' ', ship) - 1) + ' ' +
replicate('*', charindex(' ', substring(ship, charindex(' ', ship) + 1, len(ship))) + 1 -2) + ' ' +
reverse(left(reverse(ship), charindex(' ', reverse(ship)) - 1))
from outcomes
where charindex(' ', substring(ship, charindex(' ', ship) + 1, len(ship))) > 1;
select * from @ship_outcome
sorun, bunu bir kullanıcı tanımlı işlevi olmak için aşağıdaki kod kullanıldığında:
CREATE FUNCTION dbo.shippad (@tbl nvarchar(30))
RETURNS TABLE
AS
RETURN
declare @ship_outcome table
(
final_work nvarchar(30)
)
insert into @ship_outcome
select
left(ship, charindex(' ', ship) - 1) + ' ' +
replicate('*', charindex(' ', substring(ship, charindex(' ', ship) + 1, len(ship))) + 1 -2) + ' ' +
reverse(left(reverse(ship), charindex(' ', reverse(ship)) - 1))
from outcomes
where charindex(' ', substring(ship, charindex(' ', ship) + 1, len(ship))) > 1
select * from @ship_outcome
;
sistem, bu yanlış anladığımı anlayamıyorum. Lütfen yardım et.