Strings in SQL Server should be surrounded by single quotes, 'C:\ data care\test\frt.xls'
pass string with space and keyword
hi
i need to pass path to my stored porc.
i have path liek this
C:\ data care\test\frt.xls
i am getting error as i believe [DATA] is keyword and space is the issue .
how to solve it
2 answers
Sort by: Most helpful
-
-
Bert Zhou-msft 3,406 Reputation points
2022-03-31T05:00:20.537+00:00 Hi,@coool sweet
Welcome to Microsoft T-SQL Q&A Forum!
You could try this code to test :
CREATE PROCEDURE [importFile] (@filePath VARCHAR(MAX)) AS BEGIN CREATE TABLE #Temp ( column1 int, column2 varchar(10) ) DECLARE @SQL NVARCHAR(MAX) = '' SET @SQL = N' BULK INSERT #Temp FROM ''' + @filePath + ''' WITH ( FIELDTERMINATOR = '','', ROWTERMINATOR = ''\n'' )' -- ... EXEC sp_executesql @SQL END -- to run it: EXEC importFile 'C:\data care\test\frt.xls'
Best regards,
Bert Zhou
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our Documentation to enable e-mail notifications if you want to receive the related email notification for this thread.