' Age should be = 40 when Agreement Type in Automation OR Agreement Type in Bl AND Product in Personal '
Using the Above String i need to Split like below
tabl Structure
column1 Column2 Column3(Here I have to Update OR/AND )
Agreement Type Automation OR
Agreement Type Bl AND
column1 Column2 Column3(Here I have to Update OR/AND )
Agreement Type Automation OR
Agreement Type Bl AND
Need to Split from the above String in sql server 2012
this doesn't even sound like a good idea. How do you know how many columns you are going to have?
i.e. 'Age should be = 40 when Agreement Type in Automation OR Agreement Type in Bl AND Product in Personal or State = Ma'? IMO, string manipulation like this shouldn't be in the db.
There is More Work needed to get expected output !!!!!
please click arrow to the left for Drop Create Data
drop table #data
go
create table #data
(
column_string varchar(1000)
)
go
insert into #data select ' Age should be = 40 when Agreement Type in Automation OR Agreement Type in Bl AND Product in Personal '
please click arrow to the left for Function that splits strings
drop FUNCTION [dbo].[SplitStrings]
go
CREATE FUNCTION dbo.SplitStrings
(
@List NVARCHAR(MAX),
@Delimiter NVARCHAR(255)
)
RETURNS TABLE
WITH SCHEMABINDING
AS
RETURN
(
SELECT Item = y.i.value('(./text())[1]', 'nvarchar(4000)')
FROM
(
SELECT x = CONVERT(XML, '<i>'
+ REPLACE(@List, @Delimiter, '</i><i>')
+ '</i>').query('.')
) AS a CROSS APPLY x.nodes('i') AS y(i)
);
GO
select
'SQL output'
,pli.Item
from
#data as i
OUTER APPLY
dbo.SplitStrings(i.column_string,' OR ') pli