score:11
Accepted answer
Instead of using STRING_SPLIT
you can convert your string to XML and then use .value
to retrieve the 2nd element:
SELECT CAST('<t>' + REPLACE('Name1~Name2~Name3' , '~','</t><t>') + '</t>' AS XML).value('/t[2]','varchar(50)')
Read More
- Split and get second row as value
- how to get row with max value and it matches from two other tables?
- How to split only one row value and insert into multiple columns using stored procedure, parameter value is from C#
- Get count of row and sum group by quarter of date, if another column doesnt exits a value in SQL Server
- SQL Server match and get correct value from second table
- How to split string with delimiter and get the first value
score:2
Try below code:
SELECT TOP 1 T.* FROM
(SELECT TOP 2 * FROM STRING_SPLIT('Name1~Name2~Name3' , '~' ) ORDER BY value ASC) AS T
ORDER BY value DESC;
score:11
Try PARSENAME function
SELECT PARSENAME( REPLACE('Name1~Name2~Name3','~','.'),2)
output
Name2
PARSENAME Returns the specified part of an object name. The parts of an object that can be retrieved are the object name, owner name, database name, and server name.
More questions
- Get latest entry by date (year) and add Value to field from this row
- Get a value based on last and current row according to a group of conditions
- How can I select a column from my table, and get very nth row based on the value in that column in SQL Server?
- Using Split with CTE to get Even and Odd Indexed value in sql
- SQL query to parse column and get value for each parsed row
- Get second maximum number only if highest one not available in SQL and not return null value
- How to get first value from first row and last value from last row in SQL Server
- SQL Server - Split column data and retrieve last second value
- sql split row value before and after substring
- sql query to find the second '/' in the column value and split into two columns
- How can I fill a column with random numbers in SQL? I get the same value in every row
- SQL: Update a row and returning a column value with 1 query
- How to split a string after specific character in SQL Server and update this value to specific column
- Get previous and next row from rows selected with (WHERE) conditions
- MS SQL 2008 - get all table names and their row counts in a DB
- How to get the value of autoincrement of last row at the insert
- Split string into table given row delimiter and column delimiter in SQL server
- pyodbc on SQL Server - How can I do an insert and get the row ID back?
- How to get previous row value
- SQL: Get all records from one table AND a count of records from a second table?
- How to get previous and next row's value effeciently in SQL server
- SQL Left-Join - Get value If both values are Not null in TableB or Row missing in TableB
- How to get row number based on unique field and sorted by another field
- Tsql - get entire row information with max and group by
More questions with similar tag
- Finding Updated Columns from within the Stored Procedures
- Integration Services Dashboard - Out of memory
- Creating jobs in SQL Server 2008
- SSRS : Filter not working on grouped column
- Query to Join Lab Results
- The file resolves to a path that is too long. The maximum length is 260 characters
- Is there any way of adding connection parameters to all queries executed by eloquent and Laravel?
- hundreds of databases sql server log shipping
- select top from ordered query into new table
- Group by Datepart using total month daywise total orders
- SQL Query - Sum of Aggregate above a Threshold
- Get MAX() on repeating IDs
- SQL query to fetch products with most top 1 most recent price change
- SQL Server - Bulk insert without losing CR or LF characters
- Which one is better for a voting function
- SQL Connections in Azure functions
- Rebuild indexes based on fragmentation in sql server
- Merging two tables with some business logic for overfill
- Using For each In SQL Server
- Speeding up an inefficient filter
- Cast substring to int only for numeric values in SQL
- Customized processing to convert rows to Columns in SQL
- Set local variable in rdlc expression
- CASE in UPDATE produces unexpected results. Fixed when moved to WHERE clause. Why?
- I cannot sign-in Azure service from Visual Studio 2019
- GROUP BY Category and ORDER Categories
- How to print a table row wise in SQL Server?
- T-SQL pivot where clause
- creating a copy of a table without indexes
- join based on one of multiple columns
Source:
stackoverflow.com