Question

Use a variable with INLINE QUERY

  • 6 January 2023
  • 6 replies
  • 36 views

Hello, I need to use a variable in INLINE QUERIER

This is valid SQL but I can't get it to run in FME. The print is just for testing. I would ultimately use the variable as a concatenation string.

 

DECLARE @ccount as varchar(20)

 

set @ccount = (select top 1(CYCLE) from CYCLE)

 

print @ccount

 


6 replies

Userlevel 3
Badge +26

Is there a reason you are wanting to use InlineQuerier for this, instead of perhaps the Sampler to return the 1st record?

Userlevel 4

I suspect you need to use a SELECT statement to return the value of the variable.

Yes, I need to use the value in the variable as a prefix for another column

 

DECLARE @ccount as varchar(20)

 

set @ccount = (select top 1(CYCLE) from CYCLE)

select Asset_ID, @ccount + '-' + formation from TABLE

 

just a simple multi line SQL statement .

Userlevel 1
Badge +21

Yes, I need to use the value in the variable as a prefix for another column

 

DECLARE @ccount as varchar(20)

 

set @ccount = (select top 1(CYCLE) from CYCLE)

select Asset_ID, @ccount + '-' + formation from TABLE

 

just a simple multi line SQL statement .

The InlineQuerier is based on SQLLite so any SQL needs to be compatible, I don't know anything about variables but select top1 i don't think is valid SQL for SQLLite for a start.

 

Perhaps if you could explain a bit more about what you are trying to do there may be alternatives?

The InlineQuerier is based on SQLLite so any SQL needs to be compatible, I don't know anything about variables but select top1 i don't think is valid SQL for SQLLite for a start.

 

Perhaps if you could explain a bit more about what you are trying to do there may be alternatives?

I need a single attribute value.. '_2003_date' appended to an attribute in a SQL table. I think the issue is a multiline statement in Inline query.

 

So if I can pass an attribute or scalar value to inline query. I can then use it to concatenate to other columns.

 

for example. this statement in my query works.

 

select Asset_ID, SPUD_DATE, 'test_append' + Type_Curve from AllASSETS.

 

I need the value 'test_append' to be read in and not hard coded.

Badge +2

@fizquierdo1973​ Test you SQL in DB Browser for SQLite. As @ebygomm​ suggests, InlineQuerier is based on SQLite so the SQL must be SQLite compatible. SQLite Tutorial is also a great resource for understanding the nuances of SQLite's SQL.

I don't think SQLite supports declared variables

Reply