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 2008 Forums
 Transact-SQL (2008)
 String Parsing

Author  Topic 

Brittney10
Posting Yak Master

154 Posts

Posted - 2011-01-28 : 16:21:43
I'm trying to convert some queries from ACCESS to SQL. I have the following line of code that I'm having problems with:


IIf(Not IsNull([ColumnA]),Mid([ColumnA],5,InStrRev([ColumnA],"/")-5)



So, I know I'll put this in a case statement, but i'm not sure about converting the Mid and InStrRev functions to something in SQL. Any help would be much appreciated! Thanks

dataguru1971
Master Smack Fu Yak Hacker

1464 Posts

Posted - 2011-01-28 : 18:14:12

CASE WHEN ColumnA is not null
then substring(ColumnA,5,CHARINDEX('/',REVERSE(columnA))-5) else null end



Poor planning on your part does not constitute an emergency on my part.
Go to Top of Page

Brittney10
Posting Yak Master

154 Posts

Posted - 2011-01-31 : 15:35:28
Thanks! I got it working!
Go to Top of Page

dataguru1971
Master Smack Fu Yak Hacker

1464 Posts

Posted - 2011-01-31 : 15:43:19
Glad to help.



Poor planning on your part does not constitute an emergency on my part.
Go to Top of Page
   

- Advertisement -