dbTalk Databases Forums  

Query Question

microsoft.public.sqlserver.programming microsoft.public.sqlserver.programming


Discuss Query Question in the microsoft.public.sqlserver.programming forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
AGB
 
Posts: n/a

Default Query Question - 12-18-2004 , 10:31 AM






I have a table that has a column of paths that look like:

\\developmentserv\mapped\share

I am trying to run a query that will just return the \share portion
when I select that row. Not sure how to get SUBSTR to recognize the
last instance of the \ character.


Thanks


Reply With Quote
  #2  
Old   
MGFoster
 
Posts: n/a

Default Re: Query Question - 12-18-2004 , 08:46 PM






-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Probably a combination of REVERSE and PATINDEX, or CHARINDEX.

DECLARE strTemp VARCHAR(128)
SET strTemp = REVERSE(path_column)

-- Now that the string is reversed,
-- find the position of the 1st "\" char.
SET strTemp = SUBSTRING( strTemp, 1, CHARINDEX('\', strTemp) - 1 )

-- Now re-reverse the string to get the final result.
SET strTemp = REVERSE(strTemp)

--
MGFoster:::mgf00 <at> earthlink <decimal-point> net
Oakland, CA (USA)

-----BEGIN PGP SIGNATURE-----
Version: PGP for Personal Privacy 5.0
Charset: noconv

iQA/AwUBQcTrZYechKqOuFEgEQKFygCg5l5PjgvcUQKzEHFY+MQJlB JA6p8An1sI
EQk1QR5+r9GEdmv+JstCOrdZ
=AvAu
-----END PGP SIGNATURE-----


AGB wrote:
Quote:
I have a table that has a column of paths that look like:

\\developmentserv\mapped\share

I am trying to run a query that will just return the \share portion
when I select that row. Not sure how to get SUBSTR to recognize the
last instance of the \ character.

Reply With Quote
  #3  
Old   
Uri Dimant
 
Posts: n/a

Default Re: Query Question - 12-19-2004 , 12:48 AM



Hi
declare @w varchar(50)
set @w='\\developmentserv\mapped\share'
select right(@w,charindex('\',reverse(@w))-1)



"AGB" <agarrettb (AT) hotmail (DOT) com> wrote

Quote:
I have a table that has a column of paths that look like:

\\developmentserv\mapped\share

I am trying to run a query that will just return the \share portion
when I select that row. Not sure how to get SUBSTR to recognize the
last instance of the \ character.


Thanks




Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.