Solved

PATINDEX/REVERSE

Posted on 2007-04-02
2
2,078 Views
Last Modified: 2012-06-21
sql 2k5. I am using this to view a network path as a filename only. the problem is that some of the records have no path, but 'N/A'. For those records I am getting an error. select statement and error shown below.

adria
*************************************************************
Select Statement:
*************************************************************
use [spindle test]
go
select (right(imagepath_1,
      PATINDEX('%\%', REVERSE(imagepath_1))-1)) as Filename_1
from tblTD_Pics

*************************************************************
Error:
*************************************************************
Msg 536, Level 16, State 2, Line 1
Invalid length parameter passed to the RIGHT function.
0
Comment
Question by:adraughn
2 Comments
 
LVL 142

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 500 total points
ID: 18839884
select case when imagepath_1 like '%\%' then  (right(imagepath_1,
      PATINDEX('%\%', REVERSE(imagepath_1))-1)) else imagepath_1 end as Filename_1
from tblTD_Pics
0
 
LVL 13

Author Comment

by:adraughn
ID: 18839905
thanks angel. now i can go home...

adria
0

Featured Post

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

So every once in a while at work I am asked to export data from one table and insert it into another on a different server.  I hate doing this.  There's so many different tables and data types.  Some column data needs quoted and some doesn't.  What …
This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

920 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

15 Experts available now in Live!

Get 1:1 Help Now