I am NOT working with SSIS, I need to use OPENROWSET and bcp to make this work:
I am having a folder that is frequently updated with csv files which need to be imported into a database.
At the moment only ONE file is imported into the database, how can I create that process so all the files in X:\project\Input\input\ are going to be imported? Again, SSIS is not an option though it would make things easier here.
(ID)
select
case
-- when only one semi-colon---
when charindex(';',(substring(a.text,charindex(';',a.text,1)+1,99))) = 0
-- then extract the full string from first semi-colon to the max length of 99
then ltrim(rtrim(substring(a.text,charindex(';',a.text,1)+1,99)))
-- else extract the full string from the first semi-colon up to second semi-colon
else ltrim(rtrim(substring(
/* <text>> */a.text,
/* <start > */charindex(';',a.text,1) + 1,
/* <length> */charindex(';', substring(a.text, charindex(';', a.text, 1) + 1,99)) - 1
) ) )
end as ID
from openrowset(bulk 'X:\project\Input\input\input.csv',---needs to be dynamic----
formatfile = 'X:\project\Input\input\formatfile.txt',firstrow=2, format='csv'
) as a;
go