SQL Query | Split Concatenated String into Columns | CharIndex

แชร์
ฝัง
  • เผยแพร่เมื่อ 5 ต.ค. 2024
  • Hello,
    This video explains the use of CharIndex function in SQL Server to extract data from a concatenated string into different columns.
    The second part of this video will explain the use of another SQL function that can be used to achieve the same results.
    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...
    Sign up for a free trial of Coupler.io - The No code data integration tool
    app.coupler.io...
    Get USD 100 off Coursera Plus Annual Subscription
    imp.i384100.ne...
    Get 50% off Skillshare Annual Subscription with code AFF50.
    Dates: 11/24 at midnight - 11/28 at midnight
    skillshare.eqc...
    Best Data Science / Analytics / SQL courses
    Learn SQL Basics for Data Science Specialization
    imp.i384100.ne...
    Beginners to Python Programming
    skillshare.eqc...
    Data Science and Business Analytics with Python
    skillshare.eqc...
    Get 40% OFF of Skillshare with code FLASH40 - October 2022
    skillshare.eqc...
    Data Science Fundamentals with Python and SQL Specialization
    imp.i384100.ne...
    Python for Everybody Specialization
    imp.i384100.ne...
    Google Data Analytics Professional Certificate
    imp.i384100.ne...
    Coursera Plus - Data Science Career Skills
    imp.i384100.ne...
    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.c...
    Email - learn@knowstar.org

ความคิดเห็น • 52

  • @sukumar44
    @sukumar44 3 ปีที่แล้ว +6

    This is what I was looking for so many days. Finally landed to the right place. Thank you. Can you also show the same with the help of Substr() function.

    • @LearnatKnowstar
      @LearnatKnowstar  3 ปีที่แล้ว

      Thank you so much. Sure. Will post a video soon.

  • @vijay00071
    @vijay00071 3 ปีที่แล้ว +5

    CHARINDEX is not working on my SQL

  • @tarvinder91
    @tarvinder91 2 ปีที่แล้ว +2

    Thank u for explaining that embedded queries. I was able to use that knowledge in other queries.

  • @suryakota7685
    @suryakota7685 ปีที่แล้ว

    Thank you so much , for your explanation, i was asked this question in one of Big MNC

  • @lzxp7943
    @lzxp7943 2 ปีที่แล้ว

    thank you very much for break it down to step by step

  • @Beyondhorizons-i5z
    @Beyondhorizons-i5z 4 ปีที่แล้ว +2

    Brilliant stuff!

  • @latapant6371
    @latapant6371 3 ปีที่แล้ว +1

    Very useful video 🙏🙏

  • @sanujidananjaya
    @sanujidananjaya 3 ปีที่แล้ว +2

    Thank you ! , Very usefull

  • @edgetransit3320
    @edgetransit3320 3 ปีที่แล้ว +2

    You saved my life lmfao. Thank you so much !!

  • @HappyModernW3
    @HappyModernW3 3 ปีที่แล้ว +1

    Very helpful!!

  • @abhishekrawat8305
    @abhishekrawat8305 9 หลายเดือนก่อน

    please provide DDL and DML commands also

  • @TheDistractionStudio
    @TheDistractionStudio 3 ปีที่แล้ว +1

    Thank you!!

  • @lia_sahin
    @lia_sahin 3 ปีที่แล้ว +2

    how to split a large table consisting of a single column with 15 attributes, there should be 15 columns. in MsSQL server. Thanks 😊!

    • @LearnatKnowstar
      @LearnatKnowstar  3 ปีที่แล้ว +1

      There can be different approaches. One way can be to use string split function. Please see detailed tutorial here -
      th-cam.com/video/4pdNjE98R3Q/w-d-xo.html

    • @lia_sahin
      @lia_sahin 3 ปีที่แล้ว

      @@LearnatKnowstar thanks 😊

  • @pareshyadnik4108
    @pareshyadnik4108 3 ปีที่แล้ว +1

    can we use parse name function to split the string or there is a performance issue

  • @pickmeisha
    @pickmeisha 8 หลายเดือนก่อน

    My field is 'Doe,John A' and I am trying to partition the A...this is not working as it pulls over the entire name when there is no middle initial.

  • @raj-sk4br
    @raj-sk4br 3 ปีที่แล้ว +2

    What about middle name?

    • @LearnatKnowstar
      @LearnatKnowstar  3 ปีที่แล้ว

      If there is always a middle name, you can use charindex to extract the middle string. If the middle name might or might not exist, then more logic needs to be put in the SQL query.

    • @LearnatKnowstar
      @LearnatKnowstar  3 ปีที่แล้ว

      Thanks for presenting this scenario. We will post a solution video soon.

  • @solomong.gebrhana1204
    @solomong.gebrhana1204 ปีที่แล้ว

    what if we have 4 strings to extract? what is the best function to use?

  • @YouCallThataKnife253
    @YouCallThataKnife253 11 หลายเดือนก่อน

    What if I no longer want to see that original concatenated column?

  • @prashantdahiya711
    @prashantdahiya711 2 ปีที่แล้ว

    Thank you Mam, 👍

  • @tanyagupta6319
    @tanyagupta6319 2 ปีที่แล้ว

    How many possibilities these SQL queries will come in the placement? I mean same as it came ya little bit differ has to be come?

  • @Hakeem_Abdul
    @Hakeem_Abdul 2 ปีที่แล้ว

    Can you pls help me with a similar request.?? My need is: if length of input field is more than 40 characters, then it should load data until last space before 40 characters to one column and the remaining should load to another column..

  • @Dracometeor562
    @Dracometeor562 3 ปีที่แล้ว +1

    is this supported at SQL 2005 ?

  • @NaveenKumar-fq4sb
    @NaveenKumar-fq4sb 11 หลายเดือนก่อน

    where is data set ...

  • @Faisal1504
    @Faisal1504 3 ปีที่แล้ว

    What about the space between the , and first name? Don’t we add +1 to charIndex. ?

    • @LearnatKnowstar
      @LearnatKnowstar  3 ปีที่แล้ว

      Yes, you can do a +1 or apply trim on the extracted first name.

  • @prashantx19
    @prashantx19 3 ปีที่แล้ว +1

    what if there are three commas

    • @LearnatKnowstar
      @LearnatKnowstar  3 ปีที่แล้ว +1

      You can use string split function. See tutorial here
      th-cam.com/video/4pdNjE98R3Q/w-d-xo.html

    • @prashantx19
      @prashantx19 3 ปีที่แล้ว

      @@LearnatKnowstar thanks ... it really helpful.

  • @kitbodeephongkasem909
    @kitbodeephongkasem909 2 ปีที่แล้ว

    If.​ Colum.​​name.​ some.row.​ Not​ have​ comma?

  • @Manish247-R
    @Manish247-R ปีที่แล้ว

    please tell me for 2 delimiters in between.

    • @LearnatKnowstar
      @LearnatKnowstar  ปีที่แล้ว

      You can try using the Split String function.
      Please find below the video tutorial for the same -
      th-cam.com/video/4pdNjE98R3Q/w-d-xo.html

  • @shubhamgoyal5227
    @shubhamgoyal5227 ปีที่แล้ว

    Hello mam if there is middle name then then could you please guide how to derive it e.g ram kumar bansal in this how can we derive kumar using sql query.

    • @hnaidu.pro21
      @hnaidu.pro21 6 หลายเดือนก่อน

      Static Method (Name is Hardcoded):
      SELECT SUBSTRING('Ram Kumar Bansal',
      CHARINDEX(' ', 'Ram Kumar Bansal') + 1,
      CHARINDEX(' ', 'Ram Kumar Bansal', 5) - CHARINDEX(' ', 'Ram Kumar Bansal', 1)) AS MiddleName
      Dynamic Method (Applies to all names):
      SELECT SUBSTRING([Name],
      CHARINDEX(' ', [Name]) + 1,
      CHARINDEX(' ', [Name], CHARINDEX(' ', [Name]) + 1) - CHARINDEX(' ', [Name], 1)) AS MiddleName
      FROM TableName;

  • @avinashkarad7141
    @avinashkarad7141 3 ปีที่แล้ว

    i am using 11g .. i have data like below in 1 column
    col_name
    1
    john
    34000
    3
    david
    20000
    want output like in 3 different columns like this
    id name salary
    1 john 34000
    3 david 20000
    pls help me with this @Learn at Knowstar

  • @hnaidu.pro21
    @hnaidu.pro21 6 หลายเดือนก่อน

    Another Method: Using a Substring
    SELECT EmployeeID, Name,
    SUBSTRING([Name], CHARINDEX(' ', [Name], 1) + 1, LEN([Name])) AS FirstName,
    SUBSTRING([Name], 1, CHARINDEX(',', [Name], 1) - 1) AS LastName
    FROM [dbo].[tblNames]
    Method 2: Using Reverse function (along with LEFT, RIGHT)
    SELECT EmployeeID, Name,
    RIGHT([Name], CHARINDEX(' ', REVERSE([Name])) - 1) AS FirstName,
    LEFT([Name], CHARINDEX(',', [Name], 1) - 1) AS LastName
    FROM [dbo].[tblNames]