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

Notifications

Announcements

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

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Automate

#1
Michael E. Gernaey Profile Picture

Michael E. Gernaey 503 Super User 2025 Season 2

#2
Tomac Profile Picture

Tomac 321 Moderator

#3
abm abm Profile Picture

abm abm 237 Most Valuable Professional

Last 30 days Overall leaderboard