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 2000 Forums
 Transact-SQL (2000)
 string handling

Author  Topic 

fmardani
Constraint Violating Yak Guru

433 Posts

Posted - 2006-12-14 : 07:36:45
Hi,
Let's assume there is a sting that holds this value:
domainName/login

Now I would like to retrieve the login from this string.
Could you please let me know if what I am doing is the right way? It does indeed return the correct login string but not sure if this is the preoper way of handling the string in sql.
select substring(System_User, patindex('%\%', System_User) + 1, len(System_User))

Thanks

harsh_athalye
Master Smack Fu Yak Hacker

5581 Posts

Posted - 2006-12-14 : 07:41:27
Looks okay, of course you can use CHARINDEX() as well in place of PATINDEX().

Harsh Athalye
India.
"The IMPOSSIBLE is often UNTRIED"
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2006-12-14 : 10:40:52
Yes that is the proper way to do in sql
Also read about parsename in sql server help file

Madhivanan

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

Lumbago
Norsk Yak Master

3271 Posts

Posted - 2006-12-14 : 16:43:47
SELECT REPLACE(myColumn, LEFT(myColumn, CHARINDEX('/')), '')

--
Lumbago
"Real programmers don't document, if it was hard to write it should be hard to understand"
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2006-12-14 : 23:27:18
quote:
Originally posted by Lumbago

SELECT REPLACE(myColumn, LEFT(myColumn, CHARINDEX('/')), '')

--
Lumbago
"Real programmers don't document, if it was hard to write it should be hard to understand"


SELECT REPLACE(myColumn, LEFT(myColumn, CHARINDEX('/',mycolumn)), '')

Madhivanan

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

- Advertisement -