Avatar of Mehram
MehramFlag for Pakistan

asked on 

How to insert comma separated values in table

Dear Experts,
How can I insert them into the table


Declare @FeeType Varchar(100)
Set @FeeType='1,4,5'


INSERT Into #FeeTypeTemp(FeeType)
Select @FeeType
WITH
(
FIELDTERMINATOR = ',',
ROWTERMINATOR = '\n'
)
GO
Microsoft SQL Server 2008

Avatar of undefined
Last Comment
Harish Varghese
ASKER CERTIFIED SOLUTION
Avatar of Habib Pourfard
Habib Pourfard
Flag of New Zealand image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
You can insert multiple records using single INSERT statement as 'INSERT INTO table (columns) VALUES (values1), (values2), (values3), (etc)'

Try below code:
--create table #FeeTypeTemp(feetype int)

declare @values varchar(8000), @sql varchar(8000)
Select @values = '10,20,30'

select @sql = 'Insert into #FeeTypeTemp (feetype) values ('
                        + REPLACE (@values, ',', '),(') + ')'
exec (@sql)
select * from #FeeTypeTemp

-Harish
Microsoft SQL Server 2008
Microsoft SQL Server 2008

Microsoft SQL Server 2008 is a suite of relational database management system (RDBMS) products providing multi-user database access functionality.Component services include integration (SSIS), reporting (SSRS), analysis (SSAS), data quality, master data, T-SQL and performance tuning. Major improvements include the Always On technologies and support for unstructured data types.

50K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo