El siguiente código da un error (la parte de un procedimiento de T-SQL almacenado):Cómo moldear variables en T-SQL para inserción masiva?
-- Bulk insert data from the .csv file into the staging table.
DECLARE @CSVfile nvarchar(255);
SET @CSVfile = N'T:\x.csv';
BULK INSERT [dbo].[TStagingTable]
-- FROM N'T:\x.csv' -- This line works
FROM @CSVfile -- This line will not work
WITH
(
FIELDTERMINATOR = ',',
ROWTERMINATOR = '\n',
FIRSTROW = 2
)
El error es:
Incorrect syntax near the keyword 'with'.
Si sustituyo:
FROM @CSVfile
con :
FROM 'T:\x.csv'
... luego funciona bien.
Brillante, esto funcionó con solo algunas modificaciones. No pareció funcionar si utilicé alguna comilla doble en la consulta, su solución es bastante perfecta. – Contango
¿Qué sucede con la inyección de SQL? – user441365