2

Q:

I wanna to know the syntax of SQL query of inserting new line in my table.

I mean ,I wanna to enter the following in my table abc:

  aaaaaaaaaa

  bbbbbbbbbb

  cccccccccccc

Maintaining the new line.through INSERT command .

Thanks in advance

Anyname Donotcare
  • 11,113
  • 66
  • 219
  • 392
  • Usually, the best way to deal with that is with a placeholder '?' in the SQL and pass the value via a host variable when the statement is executed. This method also avoids SQL injection attacks. Failing that, the `ifx_allow_newline()` function is the way to go. – Jonathan Leffler Sep 12 '11 at 19:04

5 Answers5

6

When I answered this question, you'd got it tagged with SQL Server 2008. You've since edited it to be about Informix. The following works for SQL Server 2008.

INSERT INTO MyTable(MyField) VALUES('AAAAA' + CHAR(13) + CHAR(10) + 'BBBBB')

Informix looks more complicated. You have to set an option according to this documentation I found with a google for "informix sql newline"

EXECUTE PROCEDURE IFX_ALLOW_NEWLINE('T')
Richard
  • 29,854
  • 11
  • 77
  • 120
2

Never used informix but for SQL Server 2008 this is just.

INSERT INTO abc
            (col1)
VALUES (
'aaaaaaaaaa

bbbbbbbbbb

cccccccccccc');
Martin Smith
  • 438,706
  • 87
  • 741
  • 845
2
INSERT INTO MyTable(MyColumn) VALUES ('aaaaaaaaaa

bbbbbbbbbb

cccccccccccc');
ta.speot.is
  • 26,914
  • 8
  • 68
  • 96
1

It depends whether you're using Windows or *nix conventions, but it will be some combination of \r and \n

Have a look at the New line in Sql Query question.

Community
  • 1
  • 1
David
  • 844
  • 6
  • 14
1

why not store the row without the newline, then on the client side of your app, provide for it?

Joe R.
  • 2,032
  • 4
  • 36
  • 72