Click here to monitor SSC
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Remove Characters from String


Remove Characters from String

Author
Message
Jody Claggett-376930
Jody Claggett-376930
Valued Member
Valued Member (58 reputation)Valued Member (58 reputation)Valued Member (58 reputation)Valued Member (58 reputation)Valued Member (58 reputation)Valued Member (58 reputation)Valued Member (58 reputation)Valued Member (58 reputation)

Group: General Forum Members
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]
bitbucket-25253
bitbucket-25253
SSCertifiable
SSCertifiable (5.7K reputation)SSCertifiable (5.7K reputation)SSCertifiable (5.7K reputation)SSCertifiable (5.7K reputation)SSCertifiable (5.7K reputation)SSCertifiable (5.7K reputation)SSCertifiable (5.7K reputation)SSCertifiable (5.7K reputation)

Group: General Forum Members
Points: 5695 Visits: 25280
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
Jody Claggett-376930
Jody Claggett-376930
Valued Member
Valued Member (58 reputation)Valued Member (58 reputation)Valued Member (58 reputation)Valued Member (58 reputation)Valued Member (58 reputation)Valued Member (58 reputation)Valued Member (58 reputation)Valued Member (58 reputation)

Group: General Forum Members
Points: 58 Visits: 199
Thank you, that worked!

_______________________________
[size="5"]Jody Claggett
SQL Server Reporting Analyst
[/size]
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search