SQL Amazing Trick | Dynamically Pass Values to IN clause | Parametrize Values | String_Split

Поделиться
HTML-код
  • Опубликовано: 27 апр 2022
  • In this video tutorial, we discuss how to dynamically pass values to IN clause.
    How to install SQL Server for practice?
    • How to install SQL Ser...
    Check out the complete list of SQL Query Interview Questions -
    • SQL Query Interview Qu...
    Best Data Science / Analytics / SQL courses
    Learn SQL Basics for Data Science Specialization
    imp.i384100.net/qnXYk5
    Data Science Fundamentals with Python and SQL Specialization
    imp.i384100.net/mgVYre
    Python for Everybody Specialization
    imp.i384100.net/DVz7Aj
    Google Data Analytics Professional Certificate
    imp.i384100.net/OR37oQ
    Coursera Plus - Data Science Career Skills
    imp.i384100.net/c/3299742/132...
    Please do not forget to like, subscribe and share.
    For enrolling and enquiries, please contact us at
    Website - knowstar.org/
    Facebook - / knowstartrainings
    Linkedin - www.linkedin.com/company/know...
    Email - learn@knowstar.org

Комментарии • 49

  • @LearnatKnowstar
    @LearnatKnowstar  Год назад

    Register at the below link to get US $100 off for Coursera Plus membership between Sep 8 - Sep 29, 2022.
    The Coursera Plus membership gets you access to unlimited courses and unlimited certifications!
    imp.i384100.net/Ke51on

  • @higiniofuentes2551
    @higiniofuentes2551 9 месяцев назад

    Thank you for this very useful video!

  • @alexnevidimkins4730
    @alexnevidimkins4730 2 года назад +8

    Important point - STRING_SPLIT requires the compatibility level to be at least 130. When the level is less than 130, SQL Server is unable to find the STRING_SPLIT function.

    • @raginranga3494
      @raginranga3494 2 года назад

      I would not change Level on Prod db without research

  • @rakeshk9947
    @rakeshk9947 2 года назад +2

    Good information , But will suggest you to use trim function on value column , It will give more accurate information .

  • @nbso08
    @nbso08 2 года назад +1

    Tengo más de 20 años usando Sql Server, y nunca me dió por usar esta forma, la practicaré.
    Saludos desde Tlajo Jal Mex.

  • @ravindrasahasrabudhe8484
    @ravindrasahasrabudhe8484 2 года назад +2

    Great, this might be good for small query, the IN clause may create problem in bigger queries.
    but as this function return table, need to find out whether it can be used for populating other temp table and then use with join in bigger queries, a traditional approach for dynamic values.

    • @Belsteak
      @Belsteak 2 года назад +1

      then you use the string_split function in a join and the problem is solved.
      With even bigger table, you create a table variable with a key and then you fill that table first with the string_split then use a join.
      In 2019 normally sql will avoid the bug that considers only one row in the variable table linking to bad plan when joining. But for earlier versions the index/or key on the variable table will solve that problem.

  • @jacksparrowcapitan3232
    @jacksparrowcapitan3232 2 года назад

    Thanks for the video

  • @s0nnyv123
    @s0nnyv123 2 года назад

    Great videos! Love the pace. Subscribed!

  • @anburenganathan8369
    @anburenganathan8369 2 года назад +1

    Thanks for the video... I have one doubt i want to filter only red n black but the @var has (Red, Yellow, Grey, Black)...

  • @higiniofuentes2551
    @higiniofuentes2551 9 месяцев назад

    Do you have information about how to do this in a DB2?
    Thank you!

  • @junaidmalik9593
    @junaidmalik9593 2 года назад

    You guys r awesome, the reason being ur videos are so different and usefull in real world.

  • @HARSHAKNV95
    @HARSHAKNV95 2 года назад

    Could there be any complications that might occur if we change compatibility level?

  • @sunrathod8641
    @sunrathod8641 2 года назад

    Hi mam how we can get output header and few records ..again header after few records and details records ?

  • @higiniofuentes2551
    @higiniofuentes2551 9 месяцев назад

    Where I can find information about the select [value] from....?
    Thank you!

  • @maheshk3891
    @maheshk3891 Год назад +1

    instead in Excel=CHAR(39)&A2&CHAR(39) then for that result =CONCATENATE(B2,$B$1) . Here B1 is , . Then drill down to all the values.

  • @rutgerdekok1324
    @rutgerdekok1324 2 года назад +2

    If string_split isn't supported in your version of sql, like in mySQL, you can use:
    WHERE FIND_IN_SET(color, @var) > 0;
    or
    WHERE CONCAT(',', @var, ',') LIKE CONCAT('%,', color, ',%');

    • @katywalker8322
      @katywalker8322 2 года назад

      You can do strings_split in MySQL using substring, doing a cross join to return a list of numbers
      For example, something like this.
      SELECT SUBSTRING_INDEX(SUBSTRING_INDEX(‘some,list,of,comma,separated,values’, ‘,’, aNum), ‘,’, 1)
      FROM
      ( SELECT tens.acnt * 10 + units.acnt AS aNum
      FROM
      (SELECT 1 AS acnt UNION SELECT 2 UNION SELECT 3 UNION SELECT 4 UNION SELECT 5 UNION SELECT 6 UNION SELECT 7 UNION SELECT 8 UNION SELECT 9) units
      CROSS JOIN
      (SELECT 1 AS acnt UNION SELECT 2 UNION SELECT 3 UNION SELECT 4 UNION SELECT 5 UNION SELECT 6 UNION SELECT 7 UNION SELECT 8 UNION SELECT 9) tens
      ) AllNums
      This can be cleaned up to remove duplicates, or to cope with more than 100 comma separated values.
      Only when desperate though! Possibly useful when trying to compare values in 2 comma separated lists (after you have given the database designer a piece of your mind). Probably better to use something like this to extract to a temp table which can then be indexed.

  • @rohanthakur6136
    @rohanthakur6136 2 года назад +1

    Great 👌

  • @kashmirshadows8150
    @kashmirshadows8150 2 года назад +1

    Thank you for the video

  • @abdullahquhtani4247
    @abdullahquhtani4247 2 года назад

    Great But what if I want to use int instead of varchar ?

  • @visaalakshiselvaraj5572
    @visaalakshiselvaraj5572 2 года назад

    Very useful 🙏

  • @dimpyrathore818
    @dimpyrathore818 2 года назад

    Thank you

  • @ArabianHorse
    @ArabianHorse 2 года назад

    The Sound (voice) is not so clear. Please use a good near by ( 20 cm max ) mic or smart phone.

  • @vamshitha449
    @vamshitha449 2 года назад +1

    Write a query to get first and last row of records from table

    • @aniketjain3318
      @aniketjain3318 2 года назад

      select top 1 * from person.person
      union all
      Select * from
      (select top 1 * from person.person
      order by BusinessEntityID desc)x

    • @vamshitha449
      @vamshitha449 2 года назад

      @@aniketjain3318 is this for SQL server

    • @vamshitha449
      @vamshitha449 2 года назад

      As well as how to get particular row from a table in SQL server

    • @aniketjain3318
      @aniketjain3318 2 года назад

      @@vamshitha449 Yes. For Oracle and MySQL, you can use Limit () function.

    • @aniketjain3318
      @aniketjain3318 2 года назад

      @@vamshitha449 Solution 1: Identify the column or set of column having unique value so that you can use that value in your where clause to get the particular row from a table.
      Solution 2: Use row_number() to assign unique value to each row of the table and then using CTE, you can retrieve that particular row.

  • @mustaqahmedattar8462
    @mustaqahmedattar8462 2 года назад

    Table contains
    emp_id, first_name, last_name
    101. , Satish. , Kumar
    102. , rupesh. ,
    103. , , Chavan
    104. , ,
    Output should be
    Emo_id, name, name type
    101. , Satish, FN
    101. , Kumar, LN
    102. , rupesh, FN
    103. , Chavan, LN
    QUERY: record count of output

  • @madhavanrao3626
    @madhavanrao3626 2 года назад

    Please improve your audio quality

  • @meerasahebattar4715
    @meerasahebattar4715 2 года назад

    How to find name start with 'A' and 3rd character is not 'E'

    • @aniketjain3318
      @aniketjain3318 2 года назад

      Select * from person.Person where FirstName like 'A_[^E]%'

    • @cockbeard
      @cockbeard 2 года назад

      @@aniketjain3318 regex???? No thanks

    • @cockbeard
      @cockbeard 2 года назад +1

      WHERE CHARINDEX('A',ColName)=1
      AND SUBSTRING(ColName,3,1) 'E'
      Be wary of case sensitivity, add an OR if needed within brackets, I wouldn't use NOT IN to save a line of code because NULL values will give false positives

  • @aleksastefanovic9615
    @aleksastefanovic9615 2 года назад

    Windows 11 update is waiting for you :)

  • @georgelovell477
    @georgelovell477 2 года назад

    If your expectations are to reach US/Canadian/British audiences this delivery failed. Slow down your speech delivery. Content is not issue but it’s delivery.

  • @sunrathod8641
    @sunrathod8641 2 года назад

    Hi mam how we can get output header and few records ..again header after few records and details records ?