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
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
Thank you for this very useful video!
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.
I would not change Level on Prod db without research
Good information , But will suggest you to use trim function on value column , It will give more accurate information .
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.
Thank you. Glad it was useful.
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.
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.
Thanks for the video
Great videos! Love the pace. Subscribed!
Thank you for your support
Thanks for the video... I have one doubt i want to filter only red n black but the @var has (Red, Yellow, Grey, Black)...
Do you have information about how to do this in a DB2?
Thank you!
You guys r awesome, the reason being ur videos are so different and usefull in real world.
Thank you 🙏
Could there be any complications that might occur if we change compatibility level?
Hi mam how we can get output header and few records ..again header after few records and details records ?
Where I can find information about the select [value] from....?
Thank you!
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.
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, ',%');
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.
Great 👌
Thank you!
Thank you for the video
Thank you
Great But what if I want to use int instead of varchar ?
Very useful 🙏
Thank you
Thank you
Thank yoy
The Sound (voice) is not so clear. Please use a good near by ( 20 cm max ) mic or smart phone.
Write a query to get first and last row of records from table
select top 1 * from person.person
union all
Select * from
(select top 1 * from person.person
order by BusinessEntityID desc)x
@@aniketjain3318 is this for SQL server
As well as how to get particular row from a table in SQL server
@@vamshitha449 Yes. For Oracle and MySQL, you can use Limit () function.
@@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.
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
Please improve your audio quality
How to find name start with 'A' and 3rd character is not 'E'
Select * from person.Person where FirstName like 'A_[^E]%'
@@aniketjain3318 regex???? No thanks
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
Windows 11 update is waiting for you :)
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.
Hi mam how we can get output header and few records ..again header after few records and details records ?