Select IIF((Table.Column = "" or "" or "" or ""), (Table.Column + "TEXT"), (Table.Column))

  • Hey guys, I'm having a bit of trouble locating an operator that will set a condition if multiple values are found within a column, for example, I want to be able to look through a column, and if any of the values I am looking for in the condition are found, then I want to add text at the end of that value, if it is any other value within the column, then I simply want that value with no added text at the end. What I have in the Subject of the post might help to better understand what I am looking for, and does not work because I am using it simply as a representation of what I am trying to do. Can you use the IN operator in the SELECT statement? If so, then how? The reason I ask is that I want all of the data present and only certain data slightly changed if the condition is met. I do not think that this can be done in the where clause for the goal that I am trying to achieve. Thanks ahead of time!

  • Sounds like you want use EXISTS, but it's hard to tell without some sample data (CREATE TABLE/INSERT scripts) and an expected output.

  • gQuery - Monday, December 17, 2018 2:33 PM

    Can you use the IN operator in the SELECT statement? If so, then how? 

    IN works fine with IIF. Example:
    SELECT
    IIF(name IN ('recovery interval (min)','allow updates'),[name]+' Your text here',[name])
    FROM sys.configurations

  • SQLPirate - Monday, December 17, 2018 2:38 PM

    gQuery - Monday, December 17, 2018 2:33 PM

    Can you use the IN operator in the SELECT statement? If so, then how? 

    IN works fine with IIF. Example:
    SELECT
    IIF(name IN ('recovery interval (min)','allow updates'),[name]+' Your text here',[name])
    FROM sys.configurations

    Thank you! This is exactly what I was looking for!!!

Viewing 4 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply