Run Code
|
API
|
Code Wall
|
Users
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
Turn comma-separated numbers in string into rows
-- ============================================= -- Author: <Author,,Name> -- Create date: <Create Date,,> -- Description: <A function that splits comma separated numbers in string> -- ============================================= CREATE FUNCTION [dbo].[fnSplitValues] ( @IDs nvarchar(max) ) RETURNS @SplitValues TABLE ( ID int ) AS BEGIN -- Fill the table variable with the rows for your result set DECLARE @xml xml SET @xml = N'<root><r>' + replace(@IDs,',','</r><r>') + '</r></root>' INSERT INTO @SplitValues(ID) SELECT r.value('.','int') FROM @xml.nodes('//root/r') as records(r) RETURN END GO SELECT * FROM [dbo].[fnSplitValues]('1,2,3')
run
|
edit
|
history
|
help
0
Please
log in
to post a comment.
STACK
Sql server
/Users/svetlanakanevskaa/Downloads/ACDB.sql
Task_2_Final
FIRST DATABASE
M0413045.sql
Libros
Use the right tool to get identity values back after an insert
t1
Combined Where and having
Please log in to post a comment.