0

I need help with some Regex, please. I'm trying to use Integromat to get some data, then parse it into a format suitable for a SQL INSERT command. Integromat uses Javascript regex.

The initial data looks like this:

Identifier,Handle,Type
CS18511,big-3-jersey,men's jerseys
CS185110231,big-3-jersey,men's jerseys
CS185110232,big-3-jersey,men's jerseys
CS185110233,big-3-jersey,men's jerseys

I want to apply regex substitution to achieve this format, ideally without the heading row.

('CS18511','big-3-jersey,men''s' jerseys'),
('CS185110231','big-3-jersey,men''s jerseys'),
('CS185110232','big-3-jersey,men''s jerseys'),
('CS185110233','big-3-jersey,men''s jerseys')

I've tried the below, which seems to group the items I want, but can't find a substitution that works to create the desired output.

((?=[^\s,])(?: ?[^[\s,]+|\[[^]]*])*|(?<=,|^)(?=\s*(?:,|$)))

Any help much appreciated!

Cheers

1
  • 1
    Why???? You can insert the data directly with BULK INSERT Commented Nov 17, 2021 at 17:40

1 Answer 1

1

Here is a working example on how to use BULK INSERT

Create Table #YourTable (Identifier varchar(50),Handle varchar(50),Type varchar(50))
Bulk Insert  #YourTable FROM 'C:\Working\MyData.csv' WITH ( FIRSTROW = 2,
                                                            FIELDTERMINATOR = ',', 
                                                            ROWTERMINATOR = '\n' 
                                                          )
Select * from #YourTable

Results

Identifier   Handle         Type
CS18511      big-3-jersey   men's jerseys
CS185110231  big-3-jersey   men's jerseys
CS185110232  big-3-jersey   men's jerseys
CS185110233  big-3-jersey   men's jerseys
Sign up to request clarification or add additional context in comments.

3 Comments

Many thanks John... I wasn't aware of bulk insert. Unfortunately, the CSV data is created dynamically via an API call to our PIM, so it's not a physical file with a location to reference.
This is the failed output: CREATE TABLE PIM_DATA ( Identifier VARCHAR(100), Handle VARCHAR(100), Type VARCHAR(100) ) END BEGIN BULK INSERT PIM_DATA FROM '"Identifier,Handle,Shopify Type CS18511,big-3-jersey,men's jerseys CS185110231,big-3-jersey,men's jerseys CS185110232,big-3-jersey,men's jerseys etc...
@tbizzlebozzle bulk insert is assume a source file.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.