tsql - using if else with dynamic sql -


i new dynamic sql , trying modify existing stored proc adding if-else condition inside proc. below code

create procedure public.yeapos2q(in i_param1 character(10), in i_param2 character(8)) modifies sql data dynamic result sets 1 begin atomic         if (i_param2 null)         declare resultsingle cursor return select * employee name = i_param1;     else         declare resultsingle cursor return select * employee name = i_param1 , id = i_param2;     end if; end;; 

i following error when run it:

 hsqlexception: unexpected token: declare 

can please let me know error here?

thanks!

you don't need if in case - check null parameter in where clause:

declare resultsingle cursor  return    select * employee    name = i_param1      , (i_param2 null or id = i_param2); 

Comments

Popular posts from this blog

1111. appearing after print sequence - php -

java - WARN : org.springframework.web.servlet.PageNotFound - No mapping found for HTTP request with URI [/board/] in DispatcherServlet with name 'appServlet' -

Ruby on Rails, ActiveRecord, Postgres, UTF-8 and ASCII-8BIT encodings -