0

hei, i am getting ERROR: syntax error at or near "int" in declare.

declare v_n int; v_i int = 0
v_n := month(now()) - 1
select v_n

if object_id('tempdb..#t12345') is not null then drop table #t12345;
end if;

create temp table #t12345 (
id int identity(1,1) NOT NULL,
check_date date)

while v_i < 12
loop

if (v_n-v_i) > 0 
then
insert into #t12345(check_date)
select cast((v_n - v_i) as varchar(10)) 
'/'  
'01/' 
cast(year(now()) as varchar(20))
set; v_i = v_i + 1
else
insert into #t12345(check_date)
select cast((12 - (v_i - v_n))  as varchar(10))
'/'  
'01/'
cast((year(now()) - 1) as varchar(20))
set; v_i = v_i + 1
end if;
end loop

select * from #t12345 order by check_date desc

marked as duplicate by a_horse_with_no_name postgresql Jun 18 at 10:40

This question was marked as an exact duplicate of an existing question.

  • don't post the same question twice. You should have edited your initial question with the code you have tried. – a_horse_with_no_name Jun 18 at 10:43

Browse other questions tagged or ask your own question.