Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 string

Author  Topic 

arkiboys
Master Smack Fu Yak Hacker

1433 Posts

Posted - 2008-01-08 : 10:27:55
hi,
I receive a string into a stored procedure with machinename/domain/login

How do I get the login out of the above string please?
Thanks

TG
Master Smack Fu Yak Hacker

6065 Posts

Posted - 2008-01-08 : 10:33:44
checkout PARSENAME in Books Online.

Be One with the Optimizer
TG
Go to Top of Page

arkiboys
Master Smack Fu Yak Hacker

1433 Posts

Posted - 2008-01-08 : 10:39:37
I have tried it but it seems the parse name only works with . and not /
Any other way?
Thanks
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2008-01-08 : 10:43:26
replace / with . then parse it

or check out http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=76033


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

TG
Master Smack Fu Yak Hacker

6065 Posts

Posted - 2008-01-08 : 10:43:50
plenty. Do a search on "parsing routines"

Here is one:
http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=76033

Be One with the Optimizer
TG
Go to Top of Page

TG
Master Smack Fu Yak Hacker

6065 Posts

Posted - 2008-01-08 : 10:45:48

wow, all the parsing routines out there and we picked the same one

Be One with the Optimizer
TG
Go to Top of Page

arkiboys
Master Smack Fu Yak Hacker

1433 Posts

Posted - 2008-01-08 : 10:46:30
quote:
Originally posted by arkiboys

I have tried it but it seems the parse name only works with . and not /
Any other way?
Thanks


Solved.
Thanks
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2008-01-08 : 10:49:14
quote:
Originally posted by TG


wow, all the parsing routines out there and we picked the same one

Be One with the Optimizer
TG



I have the most efficient one bookmarked


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

TG
Master Smack Fu Yak Hacker

6065 Posts

Posted - 2008-01-08 : 11:20:21
What am I missing? I was actually looking at this function we both referenced and I noticed:

CREATE FUNCTION dbo.fnParseString
(
...
@Text TEXT
)
RETURNS VARCHAR(8000)
AS

BEGIN
....
IF @Section > 0
SELECT @Text = REVERSE(@Text)

I thought you couldn't set a TEXT datatype value using t-sql. And sure enough, I get that error when I try to compile the function in 2000.

and in 2005 I get:
"Argument data type text is invalid for argument 1 of reverse function."

I was going to reply to the function thread but I'm sure it's me...what is my problem?

Be One with the Optimizer
TG
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2008-01-08 : 18:40:28
quote:
I was going to reply to the function thread but I'm sure it's me...what is my problem?

Oh, i changed to varchar(max) in my environment, prefer not to work in text


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

saurabh122
Starting Member

16 Posts

Posted - 2008-01-09 : 00:27:21
See whether the following code helps:
-----

declare @data varchar(1000)
declare @login varchar(100)
set @data = 'domain/machine/login'
set @login = substring(@data,(charindex('/',@data,(charindex('/',@data,1)+1))+1),(len(@data)-charindex('/',@data,(charindex('/',@data,1)+1))))
print @login
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2008-01-09 : 01:49:24
quote:
Originally posted by saurabh122

See whether the following code helps:
-----

declare @data varchar(1000)
declare @login varchar(100)
set @data = 'domain/machine/login'
set @login = substring(@data,(charindex('/',@data,(charindex('/',@data,1)+1))+1),(len(@data)-charindex('/',@data,(charindex('/',@data,1)+1))))
print @login


or


declare @data varchar(1000)
declare @login varchar(100)
set @data = 'domain/machine/login'
set @login=right(@data,charindex('/',reverse(@data))-1)
print @login


Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -