Skip to main content
Announcements
Join us at Qlik Connect for 3 magical days of learning, networking,and inspiration! REGISTER TODAY and save!
cancel
Showing results for 
Search instead for 
Did you mean: 
abc_18
Creator II
Creator II

CAST in DIRECT QUERY

Hi All,

I have a doubt that when i am using CAST function in DIRECT QUERY..it's not working.

EX:->

DIRECT QUERY

SELECT

a.code_marketing_campaign
,b.[BusinessUnit__c] as 'Parent Campaign BU'
,b.[CurrencyIsoCode] as ' Parent Campaign Currency Code'
,CAST(b.[Description]) as 'Parent Campaign Description'
,CAST(b.category_marketing_campaign ) as 'Parent Campaign Type'


from (select distinct code_marketing_campaign from [WH_ID_EMEA].[dwh].[marketing_campaign]) a
inner join [WH_ID_EMEA].[dwh].[marketing_campaign] b
on a.code_marketing_campaign=b.bkey_marketing_campaign

group by
a.code_marketing_campaign
,b.[BusinessUnit__c]
,b.[CurrencyIsoCode]
,CAST(b.[Description])
,CAST(b.category_marketing_campaign );

Please suggest..

1 Reply
Ziziria
Contributor
Contributor

Hello, if you are trying to use cast just to rename a column you should just use AS, for example 

SELECT

a.code_marketing_campaign
,b.[BusinessUnit__c] as 'Parent Campaign BU'
,b.[CurrencyIsoCode] as ' Parent Campaign Currency Code'
,b.[Description] as 'Parent Campaign Description'
,b.category_marketing_campaign as 'Parent Campaign Type'

If you are trying to change the data type you have to specify the data type, like this 

SELECT

a.code_marketing_campaign
,b.[BusinessUnit__c] as 'Parent Campaign BU'
,b.[CurrencyIsoCode] as ' Parent Campaign Currency Code'
,CAST(b.[Description] as varchar(30)) as 'Parent Campaign Description'
,CAST(b.category_marketing_campaign as int) as 'Parent Campaign Type'

Hope that helps!