Home > Enterprise >  Undeclared variable DAYNAME in MYSQL
Undeclared variable DAYNAME in MYSQL

Time:11-14

I am writing a query to get count of records and name of the day of yesterday. For name of the day, I am using mysql DAYNAME(). But when I am trying to store output in an variable it's giving an error. The query is:

set @day1 = 0, @day1name = '';
select count(*) into @day1, DAYNAME(SUBDATE(current_date, 1)) into @day1name from site_stats where last_visit_on = subdate(current_date, 1);

and it's producing an error which is:

Error Code: 1327. Undeclared variable: DAYNAME

I have tried query without variable it's working fine. But when I am trying to store it into a variable it's giving 1327 error.

CodePudding user response:

You can only have one into clause, which should specify all the variables to store the selected columns in, e.g.

select count(*),DAYNAME(SUBDATE(current_date, 1)) into @day1, @day1name from ...
  • Related