Results 1 to 2 of 2

Thread: SQL Results without Spaces between columns

Hybrid View

  1. #1
    Join Date
    Jul 2022
    Posts
    1

    SQL Results without Spaces between columns

    Hello,

    I have a sql query that is selecting several columns from a table and it is contained in a file. I'm running the sql file from the command line (UNIX) and printing it to a .txt file. I'm trying to return results without any space in between each columns. Any ideas how to do this?

    My command looks likes this:
    db2 -x -tf SQLWUERY.sql > SQLOUTPUT.txt

  2. #2
    Join Date
    Aug 2022
    Posts
    22
    To remove spaces between columns in the results of a SQL query, you can use the CONCAT function to concatenate the values of each column together into a single string. Here is an example of how you can use the CONCAT function to remove spaces between columns in the results of a SELECT statement:

    SELECT CONCAT(column1, column2, column3) FROM table;

    Alternatively, you can also use the CONCAT_WS function which is used for concatenating the values of each column together into a single string and it also allows you to specify a separator. Here is an example of how you can use the CONCAT_WS function to remove spaces between columns in the results of a SELECT statement:

    SELECT CONCAT_WS('', column1, column2, column3) FROM table;

    You can also use the TRIM function to remove spaces at the beginning and end of each column value. Here is an example of how you can use the TRIM function to remove spaces between columns in the results of a SELECT statement:

    SELECT TRIM(column1) || TRIM(column2) || TRIM(column3) FROM table;

    Please keep in mind that the specific function and syntax used to remove spaces between columns in the results of a SQL query may vary depending on the specific SQL database you are using.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •