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
 General SQL Server Forums
 New to SQL Server Programming
 SUBSTRING FIND RETURN

Author  Topic 

PanzerAttack
Yak Posting Veteran

71 Posts

Posted - 2011-07-13 : 07:34:27
Hi, I've done some reading on this but I'm not quite getting it.

I have created a view and want to return the date in

Actual Version 000 /001.2009 to /001.2009 [A]
Plan Version 000 /001.2009 to /001.2009 [A]

Ideally, Find the first / and return the next 8 Characters

Is this easy to do?

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2011-07-13 : 07:41:30
declare @sample varchar(255)
set @sample = 'Actual Version 000 /001.2009 to /001.2009 [A]'
select
substring(@sample,charindex('/',@sample)+1,8)


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

PanzerAttack
Yak Posting Veteran

71 Posts

Posted - 2011-07-14 : 14:35:44
Hi Thanks for the Help.

I get this msg "The Declare cursor SQL construct or statement is not supported."

What I did was open the View in Design, paste

declare @sample varchar(255)
set @sample = 'Actual Version 000 /001.2009 to /001.2009 [A]'

Above the Select part

And then in the Design of the View I put

SUBSTRING(@sample, CHARINDEX('/', @sample) + 1, 8)

Was that right?
Go to Top of Page

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2011-07-15 : 02:10:26
@sample was only to show how it works.
In a SELECT you should use your column name.
SELECT
...
SUBSTRING(YourColumn, CHARINDEX('/', YourColumn) + 1, 8) as DateCol,
...
FROM
...



No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

PanzerAttack
Yak Posting Veteran

71 Posts

Posted - 2011-07-17 : 09:10:22
I can be so noddy. Thanks, works perfectly.
Go to Top of Page
   

- Advertisement -