Solved

Trim/Replace String

Posted on 2007-04-02
5
423 Views
Last Modified: 2011-10-03
How would I change:
\\MyServer\Optimum\Spindle\Spindle_DataBase\Pictures\Linked Pictures\173960 001.jpg

to this:
173960 001.jpg

adria
0
Comment
Question by:adraughn
  • 3
  • 2
5 Comments
 
LVL 3

Accepted Solution

by:
allennyc earned 500 total points
Comment Utility
Hi Adria,

select right('\\MyServer\Optimum\Spindle\Spindle_DataBase\Pictures\Linked Pictures\173960 001.jpg',
      PATINDEX('%\%', REVERSE('\\MyServer\Optimum\Spindle\Spindle_DataBase\Pictures\Linked Pictures\173960 001.jpg'))-1)
0
 
LVL 13

Author Comment

by:adraughn
Comment Utility
some of the fields do not have a path, only 'N/A'

i am getting this error:

Msg 536, Level 16, State 2, Line 1
Invalid length parameter passed to the RIGHT function.
0
 
LVL 13

Author Comment

by:adraughn
Comment Utility
this is what i have:

use [spindle test]
go
select (right(imagepath_1,
      PATINDEX('%\%', REVERSE(imagepath_1))-1)) as Filename_1,
(right(imagepath_2,
      PATINDEX('%\%', REVERSE(imagepath_2))-1)) as Filename_2,
(right(imagepath_3,
      PATINDEX('%\%', REVERSE(imagepath_3))-1)) as Filename_3

from tblTD_Pics
0
 
LVL 3

Expert Comment

by:allennyc
Comment Utility
Let's try to run a CASE statement to filter out the 'N/A' before we run the RIGHT function.

Hope this runs without requiring too much cleanup:

use [spindle test]
go
select      Filename_1 =
                  CASE imagepath_1
                        when 'N/A' THEN 'N/A'
                        else (right(imagepath_1, PATINDEX('%\%', REVERSE(imagepath_1))-1))
                  END,
            Filename_2 =
                  CASE imagepath_2
                        when 'N/A' THEN 'N/A'
                        else (right(imagepath_2, PATINDEX('%\%', REVERSE(imagepath_2))-1))
                  END,
            Filename_3 =
                  CASE imagepath_3
                        when 'N/A' THEN 'N/A'
                        else (right(imagepath_3, PATINDEX('%\%', REVERSE(imagepath_3))-1))
                  END
from tblTD_Pics
0
 
LVL 13

Author Comment

by:adraughn
Comment Utility
works great, thanks... :)
0

Featured Post

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Join & Write a Comment

Suggested Solutions

There are some very powerful Data Management Views (DMV's) introduced with SQL 2005. The two in particular that we are going to discuss are sys.dm_db_index_usage_stats and sys.dm_db_index_operational_stats.   Recently, I was involved in a discu…
In this article I will describe the Copy Database Wizard method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now