1

How can i hold multiline sql query in a shell variable?

SQL='Lets get CREATE TRIGGER STATEMENT'

How to hold it?

Adam Adamaszek
  • 3,914
  • 1
  • 19
  • 24
underscore
  • 6,495
  • 6
  • 39
  • 78

2 Answers2

1

This worked well for me

  extract_sql="SELECT *
               FROM TABLE"

To run SQLs with command line tools like wxsubmit or sqlplus

 commandlinesqltool  -options << EOF > /dev/null 2>&1

    SET HEADER OFF

    UPDATE TABLE
    SET    A=1;

EOF
Srini V
  • 11,045
  • 14
  • 66
  • 89
0
Declare @sql nvarchar(max);

SET @sql='SELECT *'+char(13) +'FROM table'

Print(@sql);


result: SELECT *
        FROM table

In above query char(13) will hepls to write in next line.

Now @sql variable has two lines.

koushik veldanda
  • 1,079
  • 10
  • 23
  • Are you confusing MySQL with SQL Server? Though I see that the question isn't tagged MySQL, but the chat feeds the SQL to the `mysql` program. – Jonathan Leffler Jul 09 '15 at 06:34