Getting error near IN and here is my code
DECLARE @DateFrom DateTime ='2018-04-01',
@DateTo DateTime = '2018-05-31'
WHILE @DateTo < @DateFrom
BEGIN
set @DateFrom = DATEADD(D,1,@DateFrom)
SET @DateFrom = DATENAME(DW, @DateFrom) IN ( 'tuesday','friday',null)
END
I am getting error like
Incorrect syntax near the keyword 'IN'.
If this is really mysql there are lots of errors 1) You don't declare @ variables 2) To allocate a value to a variable use a set statement or if it's a declared variable you can default a value 3) While statements syntax is incorrect it should be while something DO ... END WHILE 4) Every statement must be terminated 5) Multi code procedures must enclosed in a BEGIN..END block 5) This code must be in a stored program (procedure,trigger,function) 6) Delimiters possibly not set.
This at least syntaxs But I don't get what you are trying to do with the in statement.
drop procedure if exists p;
delimiter $$
create procedure p()
begin
set @DateFrom ='2018-04-01',
@DateTo = '2018-05-31';
WHILE @DateTo < @DateFrom do
set @DateFrom = DATEADD(D,1,@DateFrom);
SET @DateFrom = DATENAME(DW, @DateFrom) IN ( 'tuesday','friday',null);
END while;
end $$
delimiter ;
DECLARE @DateFrom DateTime ='2018-04-01',
@DateTo DateTime = '2018-05-31'
WHILE @DateTo < @DateFrom
BEGIN
set @DateFrom = DATEADD(D,1,@DateFrom)
SET @DateFrom = case when DATENAME(DW, @DateFrom) IN ( 'tuesday','friday',null) then @DateFrom else null end
END
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.