Question

I have problem mixing pattern match and curdate() function. Below is the table structure, where some of the fields current date is updated everyday. I am not sure whether they can be mixed.Please help me sort this out. Thanks.

  ta1           ta2        ta3      ta4
a20120204     20120204  20120204  20120203
a20120204123  20120204  20120203  20120203

I want my like pattern to be 'a20120204', which is current date prefixed by character 'a'.

My non-working intuitive query:

SELECT * FROM [table] WHERE ta1 LIKE 'a'+(CURDATE( ) +0)%
  • (CURDATE()+0) returns current date as YYYYMMDD
Was it helpful?

Solution

You can do it - the function you're after is CONCAT, which concatenates strings together:

SELECT *
FROM tbl
WHERE ta1 LIKE CONCAT('a',(CURDATE()+0),'%');

Note - CONCAT('a','b','%') gives 'ab%', etc.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top