Reputation: 37
I want to concatenate a part of filename in SQL.
BULK INSERT #NewSegments
FROM 'E:\scratch\AT.txt'
WITH (
FIELDTERMINATOR ='\t',
ROWTERMINATOR = '\n'
)
I want to replace AT with a parameter @CountryCode
.
Below SQL is not working.
BULK INSERT #NewSegments
FROM 'E:\scratch\' + @CountryCode + '.txt'
WITH (
FIELDTERMINATOR ='\t',
ROWTERMINATOR = '\n'
)
Upvotes: 1
Views: 560
Reputation: 13969
you might require to go for dynamic sql as below:
Declare @Query Nvarchar(max)
Set @Query = 'BULK INSERT #NewSegments FROM ''E:\scratch\'+@CountryCode+'.txt'''
WITH ( FIELDTERMINATOR =''\t'', ROWTERMINATOR = ''\n'' ) '
exec sp_executeSql @Query
Upvotes: 3