Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Qlik GA: Multivariate Time Series in Qlik Predict: Get Details
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

if else condition problem

Hello experts,

Below is the query am running in a qvw.

Note:

1.I am dynamically loading the value of a select query into a variable vtable

Is there any problem in my synatx below. my conditions are not getting checked ..by default condition is going to Else statement

Code:

=====================================================================

Let 'vTable'= 'select TableName from [dbo].[UserInput]'; //userinput could be A or B or C

if '$vTable'='A' THEN

A_Temp:
SELECT JobNumber as ABCJCJN, [JobName], [JobType], [SchedulerContactTime], [JobStartTime], [JobEndTime], [AbnormalEndTime], [AbnormalEndReason], [JobStatus], [SourceSystem], [ParameterList], [UserID], [WaitingForJobNumber], [ExtractTime], [As Of Date], [ThreadNumber], [ABCErrorReason], [Region], [AsOfDateOverrideFlag], [AppWaitingFlag], [RunBaselineToday], [IsMonthEnd], [IsQuarterEnd], [IsYearEnd], [MaintenanceLocation], [NextAsOfDate] FROM [TCRAuditBalanceControl].[dbo].[TempTable];

elseif '$vTable'='B' then

B_temp:
SELECT JobNumber as ABCEFJN, [ExtractFileName], [FolderLocation], [FileCreateTime], [NumberOfRows], [NetVolumeKBBL], [NetVolumeKT] FROM [TCRAuditBalanceControl].[dbo].[TempTable];

else

C_Temp:
SELECT [MessageNumber], [TimeStamp], JobName as ABCMJname, JobNumber as ABCMLJN, SourceSystem as ABCMSS, [Scope], AsOfDate as ABCMAOD, [MessageText], [SubSystem], [CallingProgram], [CriticalFlag] FROM [TCRAuditBalanceControl].[dbo].[TempTable];

end if

============================================================================

Your inputs appreciated

many thanks

4 Replies
Not applicable
Author

There doesnt look any problem with the condtion. it works perfect when the variable value is hardcoded with A or B or C.

i.e

Set

vTable= 'A'; or 'B'; or 'C';

The problem is that its variable is unable to get value from the select query.. i.e.

Let 'vTable'= 'select TableName from [dbo].[UserInput]'; //this fetches value A or B or C

Is there any other way to resolve





Not applicable
Author

In simple terms how can I set a variable which gets value from select query during run time of the qvw application?

Anonymous
Not applicable
Author

Here is something we use, might be a better way:


test:
SQL SELECT TableName
FROM [dbo].[UserInput];
LET vTable = FieldValue('TableName', 1);


Anonymous
Not applicable
Author

Also, when calling variables in QlikView you can't do it like this:

'$vTable'

But instead you need to call it using $(vTable) or '$(vTable)' depending on if it contains a string value or not.