0

I have a SQL that has one of the columns that stores value that begins with a hyphen '-'. When I tried to export it to csv I get an Invalid Name error. When I view it in the SQL editor it shows correctly (Sample : -Coke).

Is there anyway I could have this value saved successfully in the csv file ?

Given below is a sample view of the data

Name
-Coke
-Pepsi

Sample SQL I used:

SELECT name FROM sales WHERE name like '-%';

I am using a Redshift DB.

5
  • If you use ms excel import the file with column data format as text Commented Oct 17, 2018 at 8:00
  • 1
    So how exactly did you "export it to CSV"? Which tool did you use for that? Commented Oct 17, 2018 at 9:59
  • Very hard to give any advice unless you explain how you are exporting the data to a CSV file. Commented Oct 18, 2018 at 1:24
  • @Nathan, I am trying to export the SQL output to a csv file from the SQL editor Commented Oct 18, 2018 at 5:48
  • So, which SQL editor? And where are you seeing the "Invalid Name" error? In the SQL editor? In Excel? You might want to take a look at these tips for writing a question that gives you the best chance of getting a useful answer: stackoverflow.com/help/how-to-ask Commented Oct 18, 2018 at 19:23

2 Answers 2

1

Run the query SELECT name FROM sales WHERE name like '-%';

Select the all results and right click on it and select Copy with headers then, paste it in Excel. Now save excel as a CSV. Done...

Sign up to request clarification or add additional context in comments.

Comments

0

You can create a view with your "SELECT name FROM sales WHERE name like '-%';" query, then right click on the database and use Tasks->Export Data in ssms. "Flat file Destination" needs to be selected in "choose destination' if you need the result in csv

Comments

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.