Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Undeclared variable DAYNAME in MYSQL

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.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

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 ...
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading