New line character in Dynamic SQL.

Database

New line character in Dynamic SQL.

Hello people

I would like to know how a new line character can be used within a dynamic sql. The main purpose is to format my query which is pretty huge so that when I re-direct it into a file the dynamic query doesnt get truncated.

For eg:

Consider this SQL:

select 'select * from table.accounts where id=''Jack'' '

I want the output as:

select * from table.accounts
where id='Jack'

PS: The environment I am using is UNIX.

4 REPLIES

Re: New line character in Dynamic SQL.

It depends on the host programming language. For instance, in C or C++ you could code "\n" at any point within the string to generate a newline character.

Re: New line character in Dynamic SQL.

Thanks Jim. However, this dynamic sql is generated wit a simple bteq script i.e. a query generating a query. I used '0D0A'xc, but i guess that is the hexadecimal equivalent of EOF line character in DOS/Windows (\r\n). If my assumptions are right then I guess I should try the hexadecimal equivalent of '\n' which is EOF line character in UNIX. Any feedback guys?
gb
N/A

Re: New line character in Dynamic SQL.

it may be a bit late reply but for future references, a work around is to set foldline and line width and cast your selected columns as your line width where you want the result set to wrap.

Re: New line character in Dynamic SQL.

I have a similar kind of situation here, I want to use equivalent of newline ("/n") in my query.

Iam trying to generate a query using another query.The new query might be long enough. So I want to format my query to use newlines.Does anybody have idea on how to acheive this one.