SQL GETDATE WITH STRING HANDLING ON TEXT FIELD - TechRepublic
Question
January 27, 2008 at 04:35 AM
robmack1

SQL GETDATE WITH STRING HANDLING ON TEXT FIELD

by robmack1 . Updated 18 years, 5 months ago

I have a SQL query that I wish to select a specific field entry based on the previous month.

The purpouse of which is to run the table on a schedule without re-creating it each month.

The field I wish to interrogate contains a text string made up as follows:-

“yymm” = for example “0712” for the month of December 2007.

I can see that using a select statement of the kind … DatePart(“m”, ) = DatePart(“m”, DateAdd(“m”, -1, getdate())) AND DatePart(“yyyy”, ) = DatePart(“yyyy”, DateAdd(“m”, -1, getdate()))

…Would achieve a prior month result if the Invoicedate field is actually a date formatted field.

How would I achieve the equivalent on my table field (using string conversion)to obtain the same result.

Alas there is no actual date field in the table I am querying.

Any assistance would be much appreciated.

Many thanks,

Rob.

This discussion is locked

All Comments