views:

148

answers:

1

Current Code:

WHERE EXTRACT(YEAR_MONTH FROM timestamp_field) = EXTRACT(YEAR_MONTH FROM now())")

Instead of EXTRACT(YEAR_MONTH FROM now()), I want EXTRACT(YEAR FROM now()), but I want to hard code the month in. How do I go about concatenating the extract results with the MM month, for example 09.

I tried a few options below, with no luck.

(EXTRACT(YEAR FROM now())09)

CONCAT(EXTRACT(YEAR FROM now()), 09) 

'EXTRACT(YEAR FROM now())' + '09'
+1  A: 

You almost had it:

SELECT CONCAT(EXTRACT(YEAR FROM now()), '09');

The "+" operator is not for string concatenation, unless you use Microsoft SQL Server.

In MySQL, use CONCAT() or if you set SQL mode to ANSI or PIPES_AS_CONCAT you can use the standard "||" operator:

SET SQL_MODE := 'ANSI';
SELECT EXTRACT(YEAR FROM now()) || '09';
Bill Karwin
Doh... indeed.. Sooo close. Thanks Bill
payling