Learn SQL Server from the Best Tutors
Search in
To convert a comma-separated string into a temporary table in SQL Server, you can use a combination of string splitting and table variable or temporary table. The `STRING_SPLIT` function is available in SQL Server 2016 and later versions and is specifically designed for this purpose.
Here's an example of how you can achieve this:
```sql
-- Declare a variable to hold the comma-separated string
DECLARE @YourCommaSeparatedString VARCHAR(MAX) = 'value1,value2,value3';
-- Create a temporary table to store the values
CREATE TABLE #TempTable (Column1 VARCHAR(255));
-- Insert the values from the comma-separated string into the temporary table
INSERT INTO #TempTable (Column1)
SELECT TRIM(VALUE) AS Column1
FROM STRING_SPLIT(@YourCommaSeparatedString, ',');
-- Display the contents of the temporary table
SELECT * FROM #TempTable;
-- Drop the temporary table when you are done
DROP TABLE #TempTable;
```
Replace `'value1,value2,value3'` with your actual comma-separated string, and adjust the data type and size of the temporary table column based on your needs.
Keep in mind that the `STRING_SPLIT` function splits the string based on the specified delimiter (in this case, the comma `,`). If you are using an older version of SQL Server that does not support `STRING_SPLIT`, you might need to use a custom string splitting function or another method to achieve the same result. In such cases, various user-defined functions are available online for string splitting, or you can create your own if necessary.
Related Questions
Now ask question in any of the 1000+ Categories, and get Answers from Tutors and Trainers on UrbanPro.com
Ask a QuestionRecommended Articles
Why Should you Learn Microsoft Office
Microsoft Office is a very popular tool amongst students and C-Suite. Today, approximately 1.2 billion people across 140 countries use the office programme. It is used at home, schools and offices on a daily basis for organizing, handling and presenting data and information. Microsoft Office Suite offers programs that can...
8 Hottest IT Careers of 2014!
Whether it was the Internet Era of 90s or the Big Data Era of today, Information Technology (IT) has given birth to several lucrative career options for many. Though there will not be a “significant" increase in demand for IT professionals in 2014 as compared to 2013, a “steady” demand for IT professionals is rest assured...
Why Should you Become an IT Consultant
Information technology consultancy or Information technology consulting is a specialized field in which one can set their focus on providing advisory services to business firms on finding ways to use innovations in information technology to further their business and meet the objectives of the business. Not only does...
Top 5 Skills Every Software Developer Must have
Software Development has been one of the most popular career trends since years. The reason behind this is the fact that software are being used almost everywhere today. In all of our lives, from the morning’s alarm clock to the coffee maker, car, mobile phone, computer, ATM and in almost everything we use in our daily...
Looking for SQL Server Training?
Learn from the Best Tutors on UrbanPro
Are you a Tutor or Training Institute?
Join UrbanPro Today to find students near youThe best tutors for SQL Server Classes are on UrbanPro
The best Tutors for SQL Server Classes are on UrbanPro