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
  • 10,649
  • 59
  • 212
  • 375
  • 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
  • 28,666
  • 8
  • 72
  • 117
2

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

INSERT INTO abc
            (col1)
VALUES (
'aaaaaaaaaa

bbbbbbbbbb

cccccccccccc');
Martin Smith
  • 419,657
  • 83
  • 708
  • 800
2
INSERT INTO MyTable(MyColumn) VALUES ('aaaaaaaaaa

bbbbbbbbbb

cccccccccccc');
ta.speot.is
  • 26,445
  • 8
  • 64
  • 94
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
  • 824
  • 6
  • 14
1

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

FrankRuperto
  • 2,002
  • 4
  • 32
  • 70