Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

Remove Characters from String Expand / Collapse
Author
Message
Posted Monday, September 8, 2008 4:34 PM
Valued Member

Valued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued 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
Posted Monday, September 8, 2008 7:01 PM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: Today @ 10:29 AM
Points: 5,571, Visits: 24,775
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
Posted Tuesday, September 9, 2008 10:36 AM
Valued Member

Valued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued 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 »

Add to briefcase

Permissions Expand / Collapse