I've just done the following and it works.
SET LINESIZE 71
SET WRAP OFF
- Visitors can check out the Forum FAQ by clicking this link. You have to register before you can post: click the REGISTER link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below. View our Forum Privacy Policy.
- Want to receive the latest contracting news and advice straight to your inbox? Sign up to the ContractorUK newsletter here. Every sign up will also be entered into a draw to WIN £100 Amazon vouchers!
Collapse
You are not logged in or you do not have permission to access this page. This could be due to one of several reasons:
- You are not logged in. If you are already registered, fill in the form below to log in, or follow the "Sign Up" link to register a new account.
- You may not have sufficient privileges to access this page. Are you trying to edit someone else's post, access administrative features or some other privileged system?
- If you are trying to post, the administrator may have disabled your account, or it may be awaiting activation.
Logging in...
Previously on "SQL Question - setting a fixed record length using Spool"
Collapse
-
What are you running it on?Originally posted by Moose423956 View PostI'm trying to use the SQL spool command to set a max record length for the output file I'm spooling to. However, when the data exceeds the max record length, it just wraps the data onto the next record.
I'm looking for a way of stopping it writing the extra record, I just want it to truncate the data at the max record length. I can't see an obvious way to do this, and being new to SQL I can't work out the best way to do it. Any advice would be appreciated. Thanks.
For example:
CLEAR BREAKS
SET HEADING OFF
SET LINESIZE 71
SET ECHO OFF
SET SERVEROUTPUT OFF
SET TERMOUT OFF
SET FEEDBACK OFF
SET PAGESIZE 0
SPOOL D:\Data\outputfile.dat
SELECT *
FROM table_name;
SPOOL OFF
/
EXIT
Leave a comment:
-
Originally posted by TheFaQQer View PostSELECT SUBSTR(col1||','||col2||','||col3,1,71)
FROM foo;
No, it's not misleading - the requirement was to output no more than 71 characters, which this does. If there are more than 71 characters in the concatenated columns, then these will not appear.Originally posted by MrMark View PostAm I right in thinking this is potentially misleading? - if there are 71 characters in column 1 then you lose the data from columns 2 and 3.
SELECT SUBSTR(col1,1,23)||','||SUBSTR(col2,1,24)||','||SU BSTR(col3,1,24)
FROM foo;
(or whichever length you wanted to take from each field)
Leave a comment:
-
In SQL Server 2000 the following works:
select LEFT(columnname, 71)
from tablename
SUBSTR gives a syntax error, and you need SUBSTRING instead.
Leave a comment:
-
Just use a combo of substr (for knocking characters off) and RPAD (for adding spaces on) to fix the record at 70 characters (or whatever it is).
So
select RPAD(substr(column,1,72),72) from tablex
Leave a comment:
-
Am I right in thinking this is potentially misleading? - if there are 71 characters in column 1 then you lose the data from columns 2 and 3.SELECT SUBSTR(col1||','||col2||','||col3,1,71)
FROM foo;
SELECT SUBSTR(col1,1,23)||','||SUBSTR(col2,1,24)||','||SU BSTR(col3,1,24)
FROM foo;
(or whichever length you wanted to take from each field)
Leave a comment:
-
That will do it if there is only one column in the table.Originally posted by Moose423956 View PostI think I've done it. Instead of this:
SELECT *
FROM table_name;
do this:
SELECT SUBSTR(column_name,1,71)
FROM table_name;
which I think works because there's only one column in the table.
Otherwise:
SELECT SUBSTR(col1||','||col2||','||col3,1,71)
FROM foo;
would give you the first 71 characters of coumn1,2 and 3 separated by a comma.
Leave a comment:
-
You might be able to do it using a COLUMN ... FORMAT modifier along with SET WRAP.
SET WRAP OFF
COLUMN column_name FORMAT A71
I've not tried this so, as usual, I could be wrong.
Leave a comment:
-
I think I've done it. Instead of this:
SELECT *
FROM table_name;
do this:
SELECT SUBSTR(column_name,1,71)
FROM table_name;
which I think works because there's only one column in the table.
Leave a comment:
-
SQL Question - setting a fixed record length using Spool
I'm trying to use the SQL spool command to set a max record length for the output file I'm spooling to. However, when the data exceeds the max record length, it just wraps the data onto the next record.
I'm looking for a way of stopping it writing the extra record, I just want it to truncate the data at the max record length. I can't see an obvious way to do this, and being new to SQL I can't work out the best way to do it. Any advice would be appreciated. Thanks.
For example:
CLEAR BREAKS
SET HEADING OFF
SET LINESIZE 71
SET ECHO OFF
SET SERVEROUTPUT OFF
SET TERMOUT OFF
SET FEEDBACK OFF
SET PAGESIZE 0
SPOOL D:\Data\outputfile.dat
SELECT *
FROM table_name;
SPOOL OFF
/
EXITTags: None
- Home
- News & Features
- First Timers
- IR35 / S660 / BN66
- Employee Benefit Trusts
- Agency Workers Regulations
- MSC Legislation
- Limited Companies
- Dividends
- Umbrella Company
- VAT / Flat Rate VAT
- Job News & Guides
- Money News & Guides
- Guide to Contracts
- Successful Contracting
- Contracting Overseas
- Contractor Calculators
- MVL
- Contractor Expenses
Advertisers

Leave a comment: