Get your favorite SSC scripts directly in SSMS with the free SQL Scripts addin.
Search for scripts directly from SSMS, and instantly access any saved scripts in your
SSC briefcase from the favorites tab.
Download now (direct download link)
Thank this author by sharing:
By Luigi Marinescu,
This function has been developed by me and my friend Mihai Ciurescu.
Let's suppose that you have a web page with a listbox (multiple selection) of States and you want to get all customers having properties within your selected States. So, your page will send to the SQL Server a list of all selected State_IDs.
Now, your list of IDs is like '123,43,5465,6788,1231' and you want to split and pivot them into a table like:
Using this function now you can use its table-result to do an INNER JOIN with your_Address table (where you store the State_Id) ON .fn_SplitStringToTable.ItemData = your_Address.State_Id
This is what this
SELECT * FROM dbo.fn_SplitStringToTable('123,43,5465,6788,1231', ',')
RowIndex FromPos ToPos ItemData1 1 4 1232 5 7 433 8 12 54654 13 17 67885 18 22 1231
Luigi and Michael
Database in Recovery Pending State
Multiple States for object/entity
where is the database 'state' is stored
Error: 8355, Severity: 16, State 1