Can '%VALUE%' be written so it gets current year automaticlly

ghz 8months ago ⋅ 58 views

The query looks like this: Datatype for month.ty is text

month.ty LIKE '%2024%'

I am trying to make it get year without having to change it when year ends. Like get current year.

I have tryied with plus special character:

month.ty LIKE '%' + YEAR(current_timestamp) + '%'

This way it pops an error what ever I put inside the plus characters. Error is: Warning: #1292 Truncated incorrect DOUBLE value: '%'

Also like this:

month.ty LIKE YEAR(CURRENT_TIMESTAMP)

In this case it returns nothing. But this is probbaby since it does not go into comparing cause there is no wildcard sign '%'.

And also like this:

month.ty LIKE '%' + CAST(year(CURRENT_TIMESTAMP) AS varchar) + '%'

In this case it throws an error #1064 - You have an error in your SQL syntax;

Also tryed:

month.ty LIKE '%' + YEAR(GETDATE()) + '%'

Throws error #1558 - Column count of mysql.proc is wrong. Expected 21, found 20. Created with MariaDB 100108, now running 100421. Please use mysql_upgrade to fix this error

I am not sure if I am missing something or there is some other way for it to work. XAMPP version is 8.1.6-0 / Server version: 10.4.21-MariaDB

Answers

It seems like you're encountering issues with concatenating strings and functions in your SQL query. Let's correct the syntax and make sure the query works as intended:

month.ty LIKE CONCAT('%', YEAR(CURRENT_TIMESTAMP), '%')

In this corrected query:

  • YEAR(CURRENT_TIMESTAMP) returns the current year.
  • CONCAT('%', YEAR(CURRENT_TIMESTAMP), '%') concatenates the wildcard '%' with the current year, effectively creating a pattern to match any string containing the current year.

This should achieve the desired result of matching the month.ty column with any string containing the current year.