MySQL function returning error -


#1415 - not allowed return result set function

delimiter $$ create function test.fngetlastdaylastfinyear (pdate datetime) returns datetime begin  declare monthno int; declare yearno int;  declare outputdate datetime;      select monthno = datepart(month,@pdate);  if(@monthno <= 3)          select @yearno = (datepart(year,getdate()) - 1);           select @outputdate = date_format(@yearno,'%d/%m/%y');   else          select  @outputdate= date_format(@pdate,'%d/%m/%y'); end if;  return @outputdate; end 

if want "return" result set, must use create procedure , not create function

in docu explained can use create function when return single value.

update:

if want set variable in function , return it, suggest using

select field your-variable rest-of-normal-select; 

e.g.

declare monthno int; select datepart(month,pdate) monthno; 

this works if datepart function works expected.


Comments

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -