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
- How can I set the value and the datatype when creating a new SqlParameter?
- Calling Web Service periodically
- Invalid attempt to read data when no data is present when getting all values from a row in a SQL Server table
- Create file in Windows Explorer locking FileTable
- Recompile stored procs?
- how can i get the oppening + debit - credit = balance, in ms-sql using case
- SQL Counting column number based on first row
- TSQL Update Statement MS SQL Server 2008 R2
- How to check if a foreign column is part of a constraint with "ON DELETE CASCADE" option?
- How should we know that which logged in user is using the form in java?
- Multiple SQL SELECT WHERE with INTERSECT, placeholder value
- Make Friendlier SSRS Report URLS
- SSIS Package Not Populating Any Results
- query for identifying long rows
- Convert IIF statement from access to T-SQL SQL Server(Pass-Through)
- Is SQL Server's Remote Login Timeout setting equivalent to setting Connection Timeout value in connection string?
- run-time error '713' - Application-defined or object-defined error
- select multiple columns from two different tables, merge and then insert into another table?
- Load tables into SQL Server from SparklyR
- Combine Results from MS Access and SQL Server
- Set Limit for a Table Rows In SQL
- Parsing SOAP XML in SQL Server
- After Installing Visual Studio 2017 I am unable to debug in SQL Server Management Studio (SSMS)
- How to make my three table sql join work?
- Why is deleting records in batches better than deleting in bulk?
- stored procedure returns varchar in LINQ
- Create stored procedure. Insert data from one table into another. Execute every new entry
- Can I join two tables from different databases?
- Compare items in a SQL column with array
- PIVOT concept in sql server
Source:
stackoverflow.com