开发者

SQL Cut off string after certain number of spaces

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜