0

I'm trying to set my query result to follow format needed by javascript array. generally, the format should look like this:

[
"mydata1",
"mydata2",
]

Thus, based on my limited SQL query knowledge, this is the result that I was able to achieve so far based on this query:

SELECT '"',mydata, '",' FROM Table WHERE ID = 44946 
OR ID = 12345

However, the results will appear in 3 different columns, and it will leave some space between them.

"   2859440635959   ",
"   2749566484535   ",

Then I'll have to open notepad and remove all the spaces. Is there any other query workaround or anything that may simplify this process?

fahmijaafar
  • 175
  • 5
  • 14
  • Something like `select '"' + mydata + '"' as MyColumn from Table where Id = 44946;`? It gets more interesting if `mydata` needs to be explicitly converted to a string type and if you really want a comma-delimited list of quoted strings. It isn't quite clear. [This](https://stackoverflow.com/questions/194852/how-to-concatenate-text-from-multiple-rows-into-a-single-text-string-in-sql-serv) question may help. – HABO Feb 26 '20 at 03:46

1 Answers1

1
SELECT '"',mydata, '",' FROM Table

Based on this statement, you are creating 3 columns, namely ", mydata and ",.

In order to select a column with additional values (format). You can use concatenate function whereas, "your_data," is being concatenated as a column named RESULT.

SELECT CONCAT('"', mydata, '",') as RESULT from Table
Harrison Chong
  • 150
  • 3
  • 11
  • i'm sorry this is not what i meant. the data is clean, it is just I want to add additional characters as shown above, instead of only the numbers ie: 123 i want it to be "123",. However, if I add from the query, the result will consists of 3 different columns, so there are spaces between all added characters and the numbers. – fahmijaafar Feb 26 '20 at 02:44
  • @fahmijaafar my bad, just updated the answer, is that what you are looking for? – Harrison Chong Feb 26 '20 at 03:46
  • yes this is it. thank you so much for your guidance. – fahmijaafar Feb 26 '20 at 06:09