Skip to main content
Question

InlineQuerier sql statement question (problem with case).


Forum|alt.badge.img

Hello,

I have a following statement:

case when ($(DB_OPERATION) = 'INSERT')

then ( select max(uot.id)+1 as id, i.geometry_type as geometry_type, i.name as name, i.name as label, i.name as label_mask from unip_object_type uot cross join Inserted i)

else select * from Inserted i

end

When I run this in my workspace, I get the following error:

InlineQuerier(InlineQueryFactory): Error preparing database query: near "case": syntax error Unable to execute statement

InlineQuerier(InlineQueryFactory): Database was unable to prepare query 'case when (UPDATE = 'INSERT') then (

select max(uot.id)+1 as id, i.geometry_type as geometry_type, i.name as name,

i.name as label, i.name as label_mask

from unip_object_type uot

cross join Inserted i)

else select * from Inserted i

end

'.

InlineQueryFactory instance was not properly defined. Consult logfile for details.

InlineQuerier(InlineQueryFactory): A fatal error has occurred. Check the logfile above for details

A fatal error has occurred. Check the logfile above for details

It has to be my mistake in the case statement. When I run the query just as

select max(uot.id)+1 as id, i.geometry_type as geometry_type, i.name as name,

i.name as label, i.name as label_mask

from unip_object_type uot

cross join Inserted i

It works. However I need to run this query only when $(DB_OPERATION) (user parameter) is set to INSERT, when it is UPDATE, I need to only do select.

 

 

 

Any help is really welcome.

Thanks,

Radek

3 replies

Forum|alt.badge.img
  • Author
  • March 1, 2016

One thing I have tried was changing the word INSERT to 'INSERT' or [INSERT]... none of them works


takashi
Contributor
Forum|alt.badge.img+19
  • Contributor
  • March 1, 2016

Hi @drakez, as far as I know, CASE clause cannot be used to select a SELECT statement that should be executed. I would use a Tester to branch the data flow into two streams depending on the "DB_OPERATION" parameter value, and then use two InlineQueliers for each SELECT statement.


Forum|alt.badge.img
  • Author
  • March 1, 2016
takashi wrote:

Hi @drakez, as far as I know, CASE clause cannot be used to select a SELECT statement that should be executed. I would use a Tester to branch the data flow into two streams depending on the "DB_OPERATION" parameter value, and then use two InlineQueliers for each SELECT statement.

Hello and thanks @takashi!

My problem is - I know I can filter data based on DB_OPERATION value, however - I am trying to join two tables, where I have to use cross join (they have no common attributes). Any time I use cross join, even though one table basically does not exist, I get output data with "no_schema" - I need to have no output, not output with no_schema.

I have no idea if this clarifies what I am trying to do. When input is UPDATE - I need to merge two tables using some columns from original table, some columns from UPDATE table, when the input is INSERT, I am forced to use cross join (no common columns), so my inserted feature has id value based on max id from original table increased by one.


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings