Skip to main content
Announcements
Have questions about Qlik Connect? Join us live on April 10th, at 11 AM ET: SIGN UP NOW
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

If Statement

Hi Guys,

I am getting the below error while using the if statement. Please help me out.

select Age,

    Alias,

    City,

    if (City = 'texas','tx',city) as [newcity],

    Finisher,

    Married,

    Name,

    Notority_Level,

    wwechampion

FROM master.dbo."t_wrestlersinfo";

SQL##f - SqlState: 37000, ErrorCode: 156, ErrorMsg: [Microsoft][ODBC SQL Server Driver][SQL Server]Incorrect syntax near the keyword 'if'.

1 Solution

Accepted Solutions
Colin-Albert

QlikView is fully case sensitive, field names and the data is case sensitive. So city does not exist in your data but City does.

You have also mixed QlikView syntax and SQL syntax. You need to separate the SQL part of the script and the QlikView part.

Try this

Load *,

         if (City = 'texas','tx',City) as [newcity] ;

Sql select Age,

    Alias,

    City,

    Finisher,

    Married,

    Name,

    Notority_Level,

    wwechampion

FROM master.dbo."t_wrestlersinfo";

View solution in original post

7 Replies
sunny_talwar

Try this:

Table:

LOAD *,

          If(City = 'texas', 'tx', city) as [newcity];

select Age,

    Alias,

    City,

    Finisher,

    Married,

    Name,

    Notority_Level,

    wwechampion

FROM master.dbo."t_wrestlersinfo";

Not applicable
Author

Hi,

As sunny mentioned but small change, else part should be "City"

Table:

LOAD *,

          If(City = 'texas', 'tx', City) as [newcity];

select Age,

    Alias,

    City,

    Finisher,

    Married,

    Name,

    Notority_Level,

    wwechampion

FROM master.dbo."t_wrestlersinfo";


--Uva

Not applicable
Author

Now i am getting this error

Cannot open file 'C:\Users\hi\Desktop\master.dbo."t_wrestlersinfo"' The system cannot find the file specified.

Colin-Albert

QlikView is fully case sensitive, field names and the data is case sensitive. So city does not exist in your data but City does.

You have also mixed QlikView syntax and SQL syntax. You need to separate the SQL part of the script and the QlikView part.

Try this

Load *,

         if (City = 'texas','tx',City) as [newcity] ;

Sql select Age,

    Alias,

    City,

    Finisher,

    Married,

    Name,

    Notority_Level,

    wwechampion

FROM master.dbo."t_wrestlersinfo";

jleefjcapital
Creator II
Creator II

I have a similar question.  I'm using this If statement --

If ([seriesid] = ' x', [value]) as [Alabama] ,

I'm trying to replace [value] with [Alabama] for all records with [seriesid] = x.  Is this the correct If statement? 

Colin-Albert

Hi Jessica, you need to use something like this

     If([seriesid] = 'x', 'Alabama',  [value]) as [value]

Remember Qlik is case sensitive so you may need to test  

          if(lower([seriesid]) = 'x',  'Alabama',  [value]) as [value]

jleefjcapital
Creator II
Creator II

Thank you.  This is helpful.