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
 Deleting parts of string

Author  Topic 

jameelahr2002
Starting Member

2 Posts

Posted - 2014-03-18 : 18:54:34
The issue is that I need to delete parts of this string using SQL Server.

This string is a title of a document which should contain only the Document Category & Title. Instead, it is displaying extra parts such as Year, Date Created, etc. I would like to truncate/parse off the title. The database is Acme_system. The name of the table is dbo.documents, the column name for the title is "title" and there is also column is "childcat".

The title string reads:

2013-730-DAILY NOTES AND TRACKING FORM-11-16-13 700-030714

I want to take off everything except for "DAILY NOTES AND TRACKING FORM-11-16-13 700"

Any help you provide will be GREATLY appreciated!

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2014-03-19 : 06:25:28
--The title string reads:

--2013-730-DAILY NOTES AND TRACKING FORM-11-16-13 700-030714

--I want to take off everything except for "DAILY NOTES AND TRACKING FORM-11-16-13 700"

declare @test varchar(255)
set @test = '2013-730-DAILY NOTES AND TRACKING FORM-11-16-13 700-030714'

select
@test as origString,
reverse(stuff(reverse(stuff(@test,1,9,'')),1,7,'')) as newString



Too old to Rock'n'Roll too young to die.
Go to Top of Page

jameelahr2002
Starting Member

2 Posts

Posted - 2014-03-19 : 07:37:11
I will test this out...but should i replace the word @test with the column name which is title?
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2014-03-19 : 07:48:53
quote:
Originally posted by jameelahr2002

I will test this out...but should i replace the word @test with the column name which is title?



yes. you should


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page
   

- Advertisement -