0

I want to split a string into two tables.

I have a table named event01_eventsummary. In this table a sample entry is: "Mr. Smith | Meeting with Mrs.Smith".

Now I want the string before the delimiter (|) in the table event01_eventorganizer.

I know in MySQL I could use the MySQL SUBSTRING_INDEX() function. I can't make a xml or create a function to replicate the MySQL SUBSTRING_INDEX() function in MSSQL, because I have no direct access to the SQL Server.

Anyone know how I could get this done?

EDIT: It is not a duplicate. I tried the T-SQL Scalar function and other openly available solutions. But I can't seem to find a method that doesnt require to create a function.

1 Answers1

1

i hope this will help you

declare @temp table
(
val nvarchar(max)
)
insert into @temp values ('Mr. Smith | Meeting with Mrs.Smith');

declare @temp2 table
(
val nvarchar(max))

insert into @temp2
select LEFT(val, CHARINDEX('|', val) -1)
from @temp

select * from @temp2
wiretext
  • 3,302
  • 14
  • 19
  • Thank you! How would you do it when the value is already in the table? not inserting them? Also the table names are event01_eventorganizer & event01_eventsummary – Maximilian Rosenthal Aug 13 '15 at 10:09
  • @MaximilianRosenthal my table is temporary tables you have to replace your table instead of @temp and @temp2 something like that `insert into event01_eventorganizer select LEFT(entry, CHARINDEX('|', val) -1)from event01_eventsummary` – wiretext Aug 13 '15 at 10:20
  • I get a syntax error at insert ?! – Maximilian Rosenthal Aug 13 '15 at 10:29