web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Automate / SQL SYNTAX CONTAINS OR...
Power Automate
Answered

SQL SYNTAX CONTAINS OR LIKE

(0) ShareShare
ReportReport
Posted on by 296

Hello Community,

 

I want to filter on a column that in its rows contains a certain word of the phrase. For example "I want your" filter "want".

What syntax should I use and how should I write it in Sql?

Does it work with CONTAINS or LIKE?

I tried this, but it didn't work for me.

 

fgonzalez515_0-1661924114986.png

 

 

 

I have the same question (0)
  • Verified answer
    Mibsk Profile Picture
    49 on at

    Hi 🙂 

    I made a variable that contains the expression like this: 

    %WildCard% = %%something%%


    Then i do this in the sql string: 
    ......AND json_data LIKE '%WildCard%'

  • fgonzalez515 Profile Picture
    296 on at

    Hi @Mibsk,

     

    Thank you, got a good result.

     

    Can you help me with the following?

     

    When I write the syntax individually, I get a result.

    fgonzalez515_1-1661950373468.png

     

    But when I write the syntax together, I get no results

    fgonzalez515_2-1661950508525.png

     

     

     

  • Mibsk Profile Picture
    49 on at

    Its hard to 100% tell when i cant test against your sql server. 
    But it seem like you have " # " where you should have " ' "
    #%FormattedDateTime%# looks like it should be '%FormattedDateTime%' etc.

  • fgonzalez515 Profile Picture
    296 on at

    When I made that change it gave me an error.

     

    In SQL Instruction, from row 4 to 6, the filter does not work for me

  • Verified answer
    dchen Profile Picture
    19 on at

    When using the method of adding 

    %%something%% to the %wildcard% variable, it doesn't work.  The SQL didn't give an error, but the results are wrong.

  • Mibsk Profile Picture
    49 on at

    Since the method will work if used correctly, I think you need to reply with the SQL string that you are using, so that we can help you in the right direction.

  • dchen Profile Picture
    19 on at

    Here's a SELECT statement.  If I escaped '%' with '%%', it will run and still list all records.  It doesn't seem to filter the records.

     


    SELECT a.SyCampusID,b.FirstName,b.LastName
    FROM AdEnroll a (nolock)
    inner join SyStudent b (nolock)
    on a.SyStudentID = b.SyStudentId
    inner join SySchoolStatus c (nolock)
    on a.SySchoolStatusID = c.SySchoolStatusID
    inner join SyCampus d (nolock)
    on a.SyCampusID = d.SyCampusID
    where a.SySchoolStatusID in ( 67, 68, 72, 103, 104, 106, 108, 70, 96, 107, 105, 109, 110 )
    and DATEDIFF( day, GETDATE(), a.ExpStartDate ) < 63
    and a.ExpStartDate between '10-24-2022' and '10-24-2022 11:59pm'
    and a.AdShiftID = 18
    and b.OtherEmail not like '%gmail.com%'
    and b.email not like '%gmail.com%'

  • Mibsk Profile Picture
    49 on at

    Hi again 🙂 
    Well. have you tried the SQL statement directly in SQL Management studio?
    And did you then get the wished result?

    Have you tried doing exactly what i was doing in the answer? 
    Parsing gmail.com into a variable before using it in the SQL statement?
    %WildCard% = %%gmail.com%%
    (Should not matter at all if you do it like this or directly escape it in the SQL statement as you mention, but give it a try anyways...)

    Finally, if you output the result SQL statement inside PowerAutomate does it then look as a valid SQL statement. 
    Maybe try outputting the SQL statement inside a variable and then use SQL Management Studio to test if it is even valid 🙂

    Good luck 

  • Mibsk Profile Picture
    49 on at

    I typed an error in this answer.... You need to have the desired string typed with 3 % like this: %%%string%%% if you use variable. 
    Then you can call it inside the sql statement as normal LIKE '%variable%'.

     

    This works because you escape the % by using double of them. 
    Try using 3 of them in the variable. 
    Should work.

  • dchen Profile Picture
    19 on at

    Yes.  The script works if we ran it directly from SQL.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Users!

Kudos to our 2025 Community Spotlight Honorees

Congratulations to our 2025 community superstars!

Congratulations to the April Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Automate

#1
Vish WR Profile Picture

Vish WR 957

#2
Valantis Profile Picture

Valantis 847

#3
Haque Profile Picture

Haque 609

Last 30 days Overall leaderboard