Log in
::
Register
::
Not logged in
Home
Tags
Articles
Editorials
Stairways
Forums
Scripts
Videos
Blogs
QotD
Books
Ask SSC
SQL Jobs
Training
Authors
About us
Contact us
Newsletters
Write for us
Recent Posts
Recent Posts
Popular Topics
Popular Topics
Home
Search
Members
Calendar
Who's On
Home
»
SQL Server 2005
»
T-SQL (SS2K5)
»
Remove Characters from String
Remove Characters from String
Rate Topic
Display Mode
Topic Options
Author
Message
Jody Claggett-376930
Jody Claggett-376930
Posted Monday, September 08, 2008 4:34 PM
Valued Member
Group: General Forum Members
Last Login: Thursday, March 28, 2013 12:21 PM
Points: 58,
Visits: 199
I have a set of data that gives me month name and year in this format:
FiscalMonth
July, 2008
August, 2008
September, 2008
I need to select only the month name part of the string, so everything from the comma to the right needs to be excluded.
I tried searching for a forum subject on this, but couldn't find anything. If there is another post with information on this, please let me know.
Thank you.
_______________________________
[size="5"]Jody Claggett
SQL Server Reporting Analyst
[/size]
Post #565829
bitbucket-25253
bitbucket-25253
Posted Monday, September 08, 2008 7:01 PM
SSCertifiable
Group: General Forum Members
Last Login: Yesterday @ 7:13 PM
Points: 5,103,
Visits: 20,214
To select just the month, that is data to the left of the first comma try this code to give you an idea of what you can do:
DECLARE @FM as VARCHAR(10)
DECLARE @Indata AS VARCHAR(20)
SET @Indata = 'July, 2008'
SET @FM = (SELECT(SUBSTRING(@Indata,1,(CHARINDEX(CHAR(44), @indata)-1))))
PRINT 'For testing fiscal month is*' + @FM + '*'
at this point the variable @FM contains what you want and you can then insert this into a column in a table, use the set statement in a function or use it as you wish.
I included:
PRINT 'For testing fiscal month is*' + @FM + '*'
so that you can verify your results before using, of course in actual use you will not include the PRINT statement
CHAR(44) is the ASCII comma.
If everything seems to be going well, you have obviously overlooked something.
Ron
Please help us, help you -before posting a question please
read
Before posting a performance problem please
read
Post #565849
Jody Claggett-376930
Jody Claggett-376930
Posted Tuesday, September 09, 2008 10:36 AM
Valued Member
Group: General Forum Members
Last Login: Thursday, March 28, 2013 12:21 PM
Points: 58,
Visits: 199
Thank you, that worked!
_______________________________
[size="5"]Jody Claggett
SQL Server Reporting Analyst
[/size]
Post #566311
« Prev Topic
|
Next Topic »
Permissions
You
cannot
post new topics.
You
cannot
post topic replies.
You
cannot
post new polls.
You
cannot
post replies to polls.
You
cannot
edit your own topics.
You
cannot
delete your own topics.
You
cannot
edit other topics.
You
cannot
delete other topics.
You
cannot
edit your own posts.
You
cannot
edit other posts.
You
cannot
delete your own posts.
You
cannot
delete other posts.
You
cannot
post events.
You
cannot
edit your own events.
You
cannot
edit other events.
You
cannot
delete your own events.
You
cannot
delete other events.
You
cannot
send private messages.
You
cannot
send emails.
You
may
read topics.
You
cannot
rate topics.
You
cannot
vote within polls.
You
cannot
upload attachments.
You
may
download attachments.
You
cannot
post HTML code.
You
cannot
edit HTML code.
You
cannot
post IFCode.
You
cannot
post JavaScript.
You
cannot
post EmotIcons.
You
cannot
post or upload images.
Copyright © 2002-2013 Simple Talk Publishing. All Rights Reserved.
Privacy Policy.
Terms of Use.
Report Abuse.