Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Extracting Everything From Right of A Group of Characters

0 views
Skip to first unread message

meredithhitchcock

unread,
Nov 19, 2009, 11:21:55 AM11/19/09
to
Hi all--

So I've got a field, and I need to extract all characters to the right of the group of characters -1\.

I created a right function but it gives me some random result where -1\ is in the middle of the result.

So I think I screwed something up.

Any help?

Thanks so much!

EggHeadCafe - Software Developer Portal of Choice
BizTalk Application that inserts records into SQL from *.CSV File
http://www.eggheadcafe.com/tutorials/aspnet/6a535c9b-a5ee-46c8-9836-5dd6aefc6571/biztalk-application-that.aspx

meredithhitchcock

unread,
Nov 19, 2009, 11:25:13 AM11/19/09
to
Hi all--

So I've got a field, and I need to extract all characters to the right of the group of characters -1\.

I created a right function but it gives me some random result where -1\ is in the middle of the result.

So I think I screwed something up.

Any help?

Thanks so much!

EggHeadCafe - Software Developer Portal of Choice

Extending a TextBox Control in ASP.NET
http://www.eggheadcafe.com/tutorials/aspnet/abfc302a-e9b7-4b43-8919-d47cfb4b6482/extending-a-textbox-contr.aspx

Simon Whale

unread,
Nov 19, 2009, 11:35:44 AM11/19/09
to
could do with nowing the following

1. Query that has the problem
2. some sample data to work it on
3. SQL Server version

Many Thanks
Simon

<Meredith Hitchcock> wrote in message
news:20091119112152me...@gmail.com...

Plamen Ratchev

unread,
Nov 19, 2009, 12:26:52 PM11/19/09
to
See this example:

CREATE TABLE Foo (
keycol INT PRIMARY KEY,
datacol VARCHAR(20));

INSERT INTO Foo VALUES(1, 'abc-1\def');
INSERT INTO Foo VALUES(2, 'abcdef');
INSERT INTO Foo VALUES(3, 'abc-1\');
INSERT INTO Foo VALUES(4, 'abc-1\d');


SELECT keycol, datacol,
CASE WHEN CHARINDEX('-1\', datacol) > 0
THEN STUFF(datacol, 1, CHARINDEX('-1\', datacol) + 2, '')
END AS right_side
FROM Foo;

/*

keycol datacol right_side
----------- -------------------- -----------
1 abc-1\def def
2 abcdef NULL
3 abc-1\
4 abc-1\d d

*/

DROP TABLE Foo;

--
Plamen Ratchev
http://www.SQLStudio.com

Frank Uray

unread,
Nov 19, 2009, 1:47:03 PM11/19/09
to
Hi Meredith

I am not exactly sure what you mean,
can you provide a sample ?

Did you look to the CHARINDEX function ?

Regards
Frank Uray

"Meredith Hitchcock" wrote:

> .
>

0 new messages