になります。例えば
Declare @YourTable table (ID int,Fruit varchar(150))
Insert into @YourTable values
(1,'Banana/Pear/Orange'),
(2,'Pear/Raspberry/Apple'),
(3,'Banana')
Select A.ID
,B.Key_Value
From @YourTable A
Cross Apply (Select * from [dbo].[udf-Str-Parse](A.Fruit,'/')) B
戻り
ID Key_Value
1 Banana
1 Pear
1 Orange
2 Pear
2 Raspberry
2 Apple
3 Banana
UDF
CREATE FUNCTION [dbo].[udf-Str-Parse] (@String varchar(max),@Delimeter varchar(10))
--Usage: Select * from [dbo].[udf-Str-Parse]('Dog,Cat,House,Car',',')
-- Select * from [dbo].[udf-Str-Parse]('John Cappelletti was here',' ')
Returns @ReturnTable Table (Key_PS int IDENTITY(1,1), Key_Value varchar(max))
As
Begin
Declare @XML xml;Set @XML = Cast('<x>' + Replace(@String,@Delimeter,'</x><x>')+'</x>' as XML)
Insert Into @ReturnTable Select ltrim(rtrim(String.value('.', 'varchar(max)'))) FROM @XML.nodes('x') as T(String)
Return
End
ありがとうございました!私の実際のデータベースは果物の笑を少し複雑にしています。ありがとう – user3697498
varcharで.valueを使用できますか? – user3697498
@ user3697498はい –