Re: Find between char field

From: Geoff Muldoon <geoff.muldoon_at_trap.gmail.com>
Date: Tue, 26 Apr 2016 14:57:25 +1000
Message-ID: <dwkrkozgkalb.1ci3v4hkp658k$.dlg_at_40tude.net>


On Tue, 26 Apr 2016 06:29:10 +0200, J.O. Aho wrote:

> On 04/25/2016 10:19 PM, Jerry Stuckle wrote:

>> On 4/25/2016 10:04 AM, wilsonfalai_at_gmail.com wrote:
>>> I have a char field where I keep month and year as follows: 01/2015 or 02/2015 or 12/2015 or 03/2016 ...
>>> I want to do a search and return all records from a period
>>> Example:
>>>
>>> SELECT ... AND (`periodo_referente` BETWEEN '01/2016' AND '04/2016')
>>>
>>> As I have a record for each period (month / year) , should return me 01/2016 , 02/2016 , 03/2016 and 04/2016 . But this search is wrong because returns record where the period is 01/2015 and the other a period unwanted
>>>
>>> Could anyone help me solve this select?
>>>
>>
>> J.O. has a good solution. But if you can change your columns, I would
>> recommend changing this to 201604 or 2016/04. This would make it much
>> easier to compare.
>>
>> A column for year and one for month can work, but it can get awkward if
>> you want to select dates between, i.e. 11/2014 and 02/2016.
>>
> 
> Yes, thas a slight draw back there as it would require two between, one
> for year and one for month.

Or still just one "between" on CONCAT(year, month) ...

GM Received on Tue Apr 26 2016 - 06:57:25 CEST

Original text of this message