开发者

SQL Cut off string after certain number of spaces

开发者 https://www.devze.com 2023-01-12 23:43 出处:网络
I have a string that always reads as follows: re-assigning LastName,FirstName re-assigned the order to LastName, FirstName (Administrator)Reason Code: Reassign orderComment:

I have a string that always reads as follows:

re-assigning LastName, FirstName re-assigned the order to LastName, FirstName (Administrator) Reason Code: Reassign order Comment:

The name is always diffent but I only want to return the LastName, Firstname part on the first occ开发者_开发技巧urence so right after re-assigning. The spaces and everything is exactly how it appears when it is printer except the Lastname, FirstName is normally a name of course.

Any Ideas?

Thanks!


declare @x varchar(max)

set @x = 're-assigning LastName,  FirstName re-assigned the order to LastName, FirstName (Administrator)  Reason Code: Reassign order  Comment:   '

select SUBSTRING(@x,14,PATINDEX('%re-assigned%',@x)-15) 

Returns "LastName, FirstName"

Is that what you need?

0

精彩评论

暂无评论...
验证码 换一张
取 消