You recently told me how to pad the output from a copy table statement. I cannot get the syntax to work, can you take a look and what I am doing wrong. The code is:
procedure create_export_textfile(strChosen = Array of StringObject default null, EiacCode = VarChar(10) not null) =
declare
k = smallint not null;
OutputFile = StringObject;
OutputString = StringObject;
XA = StringObject;
XAHeader = StringObject;
XASpace = StringObject;
ErrorStatus = integer not null;
NameOfTable = char(3) not null;
vstring = varchar(3000) NOT NULL;
fromClause = varchar(18) not null;
From what you have said before I think I need to state all the columns in that table i.e. ‘As select from table etc’ then list columns as below. The field altlcnxb I set as shown to make it 2 characters padded at the front so that it will display 00, 01, 02 etc. Then in the copy statement below I am hoping it will copy out the ‘padded’ value for this field. However, I do not understand the syntax, I have tried what is shown below and other configurations, but to no avail, could you give an example of the correct syntax below.
I see here many syntax issues :
1/ you could not use the star (*) you must write the name of each columns (see in my previous example)
2/ AS eiacodxa ' + + lsaconxb + : contain 2 + sign with nothing inside
During your test, please do the following :
- print vstring before each execution
- if your program go down with an SQL error you will be more comfortable to correct syntax issue
Padding explanation
The SQL expression : right('0' + varchar(altlcnxb),2)
Let's have a look of separate functions :
1/ varchar(altlcnxb) : convert your numeric data into varchar
2/ '0' + : to add the first zero if altlcnxb is less equal to 9
3/ right(expression,2) : extract the 2 rightest caracters (or the two last) of the chain given by the expression "'0' + varchar(altlcnxb)"
* altlcnxb 2 digits (altlcnxb = 11)
1/ varchar(altlcnxb) = '11'
2/ '0' + varchar(altlcnxb) = '0' + '11' = '011'
3/ right('0' + varchar(altlcnxb),2) = right('0' + '011',2) = '11'
=> '11' do not need to be padded, so the 2 last position represent your number ...