Six Stars

Problems to handle context variables

Hallo,

I'm a newbie to Talend and Java. My problem is, how use context variables in a MSSQLInput component.

SELECT TOP (10)

       Upper([ResourceCspId])

      ,[Resource]

      ,([Quantity]) as 'Menge'

      ,[ResourceGroupName] as 'ResourceGrp'

      , [CustomerName] as 'Kunde'

      ,CONVERT(VARCHAR(10), [UsageStartUtc], 105) as 'Datum'

      ,'"+CSPBilling.DatumVon+"' as 'von'

      ,'"CSPBilling.DatumBis"' as 'bis'   

 FROM [csp].[AzureKosten]

 

In this example are 2 context variables CSPBilling.DatumVon  and CSPBilling.DatumBis. The variables are string and hold dates in the yyyy-mm-dd format. My problem is, that the variables will be replaced in runtime. I added some screenshots to show the situation (definition of the variables and result of the query. Thank you for any help.

 

regs

 

HuContext Pararameter.jpgContexResult.jpg

 

1 ACCEPTED SOLUTION

Accepted Solutions
Seven Stars

Re: Problems to handle context variables

you use the object name as context and not the name of the context you have defined, so your query shud look like this
"SELECT TOP (10)

Upper([ResourceCspId])

,[Resource]

,([Quantity]) as 'Menge'

,[ResourceGroupName] as 'ResourceGrp'

, [CustomerName] as 'Kunde'

,CONVERT(VARCHAR(10), [UsageStartUtc], 105) as 'Datum'

,'"+context.DatumVon+"' as 'von'

,'"+context.DatumBis+"' as 'bis'"
4 REPLIES
Seven Stars

Re: Problems to handle context variables

you use the object name as context and not the name of the context you have defined, so your query shud look like this
"SELECT TOP (10)

Upper([ResourceCspId])

,[Resource]

,([Quantity]) as 'Menge'

,[ResourceGroupName] as 'ResourceGrp'

, [CustomerName] as 'Kunde'

,CONVERT(VARCHAR(10), [UsageStartUtc], 105) as 'Datum'

,'"+context.DatumVon+"' as 'von'

,'"+context.DatumBis+"' as 'bis'"
Six Stars

Re: Problems to handle context variables

?Hi,


sorry it doesn't work. Same result.

Six Stars

Re: Problems to handle context variables

Can you try using "tContextLoad" component as you are loading context variables from external sources?

Six Stars

Re: Problems to handle context variables

Now it is working. Thank you for helping me.

regs