I have tried to call the SQL stored procedure with output parameter within a CL program using QZDFMDB2 to run SQL interactively in a CL program and I have succeeded a lot in that. Now, I can call the SQL stored procedure with the output parameter in the CL program, the only drawback that I face is IRead more
I have tried to call the SQL stored procedure with output parameter within a CL program using QZDFMDB2 to run SQL interactively in a CL program and I have succeeded a lot in that. Now, I can call the SQL stored procedure with the output parameter in the CL program, the only drawback that I face is I am not getting the output parameter value returned in my CL program.
To call the SQL stored procedure with output parameter in the CL program I have used the, so I created a SQL variable and passed that as a return parameter in the form of a command string to program QZDFMDB2 that allows to run SQL statements in CL program. This makes my first work done i.e. calling a SQL stored procedure in a CL program with output parameters which earlier seemed very difficult or almost impossible. So congrats for this success that we have achieved so far.
Now, the turn is for receiving the return value in the output parameter which is SQL variable here. So, it was sad but we are not getting return value from SQL stored procedure in our CL program. So, I decided to use some tricks and tweaks so that I would anyway receive the return value or value returned by the output parameter SQL stored procedure in my CL program. Let me show you the code and steps that I followed to achieve this:
Create a SQL variable using the CREATE VARIABLE statement from STRSQL.
create or replace variable out char(1) default ' '
Write a SQL stored procedure that returns the output parameter.
CREATE OR REPLACE PROCEDURE STORED33(
IN P_NAME CHAR(20),
IN P_GENDER CHAR(1),
OUT SUCCESS CHAR(1)
)
SPECIFIC STORED33
BEGIN
DECLARE SQLSTATE CHAR(5) DEFAULT ' ';
DECLARE SQLCODE INTEGER DEFAULT 0;
DECLARE STMT CHAR(500) DEFAULT ' ';
INSERT INTO PF8_D(NAME,GENDER) VALUES(P_NAME,P_GENDER);
IF SQLCODE = 0 THEN
SET SUCCESS = '1';
SET STMT = 'CREATE OR REPLACE VARIABLE TESTLIB.OUT '
CONCAT 'CHAR(1) DEFAULT ''1''';
EXECUTE IMMEDIATE STMT;
ELSE
SET SUCCESS = '0';
SET STMT = 'CREATE OR REPLACE VARIABLE TESTLIB.OUT '
CONCAT 'CHAR(1) DEFAULT ''0''';
EXECUTE IMMEDIATE STMT;
END IF;
END
In the SQL stored procedure code, a few lines are written intentionally such as we are writing create or replace SQL variables and setting their values as 1 or 0 according to SQL code value. Here, the SQL variable works as a return value for my CL program. Please note that SQL variable value is accessible to the same session in which its value is set by default during the create variable statement or SET statement.
Compile the SQL stored procedure using the RUNSQLSTM command.
Please, note that in step 1 we created a SQL variable named OUT in the TESTLIB library so that we can later create a view RTNVAL in qtemp library using that at step 4. For your knowledge as we have declared the view rtnval in my CL program so that I can populate that view with the value that was set by SQL stored procedure in SQL variable (SQL global variable).
At the beginning of the program, we create an SQL variable out in testlib with a default blank value by passing the create or replace variable statement to the QZDFMDB2 program as a parameter in the string format.
Then, we call the SQL stored procedure from within the CL program with input and output parameters by first building the &cmd string, and in, we pass the SQL variable instead of any CL program variable. Then we pass it to the QZDFMDB2 program as a parameter to run the SQL stored procedure. Now till this point, we have not received any return value from the SQL stored procedure call using QZDFMDB2. However, within the SQL stored procedure script, we did set the respective success/failure value in the SQL variable globally and now I am ready to receive that in my CL program which would be the actual return value by my SQL stored procedure call.
So, I selected the global SQL variable value and output it in a view named rtnval, and after that, I just read the view using the RCVF command and evaluated the value from the view column &rtn to the cl program variable &sqlout. Therefore, &sqlout would not contain the return value or the output parameter value that should be returned by the actual SQL stored procedure call within the CL program with the output parameter
Declare global temporary table statement defines a temporary table for the current session. The temporary table when declared then it is created in the work file database and its description is not populated in the system catalog files. This global temporary table cannot be shared with other sessionRead more
Declare global temporary table statement defines a temporary table for the current session. The temporary table when declared then it is created in the work file database and its description is not populated in the system catalog files. This global temporary table cannot be shared with other sessions. Once the session ends, the global temporary table is dropped.
Sample fully free sqlrpgle program to declare global temporary table.
**free
exec sql
drop table session.gtm1;
exec sql
declare global temporary table session.gtm1 as
(select * from pf1) with data;
return;
Compiling and running this code will create a file GTM1 in the QTEMP library. select * from qtemp.gtm1
We can call SQL stored procedure from within the CL program using the QZDFMDB2 program which is the datalink file manager DB2 CLP program present in the QSYS library. pgm dcl var(&cmd) type(*char) len(200) dcl var(&in1) type(*char) len(20) value('test') dcl var(&in2) type(*char) len(1) vRead more
We can call SQL stored procedure from within the CL program using the QZDFMDB2 program which is the datalink file manager DB2 CLP program present in the QSYS library.
We need to build the command string which is the SQL stored procedure CALL statement with the required parameter. Later we pass that command string to the program qzdfmdb2 which executes SQL interactively from within the CL program.
When we call a SQL stored procedure using a constant value instead of a parameter marker (?) sqlcode -469 is returned. You can call a SQL stored procedure by passing a parameter marker in an INOUT parameter like this. call testlib.STORED33A('name1','M','?') However, you cannot even call using a paraRead more
When we call a SQL stored procedure using a constant value instead of a parameter marker (?) sqlcode -469 is returned.
You can call a SQL stored procedure by passing a parameter marker in an INOUT parameter like this.
call testlib.STORED33A('name1','M','?')
However, you cannot even call using a parameters marker in the STRSQL session on an IBM i machine as the Use of parameter marker, NULL, or UNKNOWN is not valid.
However, You can call it by passing any value to the OUT or INOUT parameter from the Run SQL script like call testlib.STORED33A('name1','M',NULL); call testlib.STORED33A('name1','M',' '); call testlib.STORED33A('name1','M',5); call testlib.STORED33A('name1','M',?);
You will get the return output.
[ 26/08/2024, 01:11:27 am ] Run Selected...
call testlib.STORED33A('name1','M',NULL)
Return Code = 0
Output Parameter #3 (SUCCESS) = 1
Statement ran successfully (339 ms)
[ 26/08/2024, 01:14:45 am ] Run Selected...
call testlib.STORED33A('name1','M',' ')
Return Code = 0
Output Parameter #3 (SUCCESS) = 1
Statement ran successfully (294 ms)
[ 26/08/2024, 01:16:55 am ] Run Selected...
call testlib.STORED33A('name1','M',5)
Return Code = 0
Output Parameter #3 (SUCCESS) = 1
Statement ran successfully (295 ms)
[ 26/08/2024, 01:30:05 am ] Run Selected...
call testlib.STORED33A('name1','M',?)
Return Code = 0
Output Parameter #3 (SUCCESS) = 1
Statement ran successfully (293 ms)
No such issue will occur when you call the SQL stored procedure from the Run SQL Script. This issue will only occur in the STRSQL session. Therefore, to call it from the STRSQL session you first have to create a SQL global variable using CREATE VARIABLE statement like below.
The variableSQLOUT was created in testlib. It’s an *SRVPGM object type of attribute CLE.
Now again try to call the SQL stored procedure from the STRSQL session on IBM i but this time passed the SQL global variable for the OUT or INOUT parameter in the procedure as below.
ILE RPG data types mapped to SQL data types: ILE RPG data type Description SQL data type DS Data structure Char Zoned(digits:decimal places) Zoned data Numeric(digits, decimal places) Packed(digits:decimal places) Packed data Decimal(digits, decimal places) Bindec(digits) 2-byte binary with 0 decimaRead more
ILE RPG data types mapped to SQL data types:
ILE RPG data type
Description
SQL data type
DS
Data structure
Char
Zoned(digits:decimal places)
Zoned data
Numeric(digits, decimal places)
Packed(digits:decimal places)
Packed data
Decimal(digits, decimal places)
Bindec(digits)
2-byte binary with 0 decimal places
smallint
2-byte binary with 0 decimal places
4-byte binary with 0 decimal places
Integer
Int(5)
2-byte integer
smallint
Int(10)
4-byte integer
Integer
Int(20)
8-byte integer
Bigint
Float(4)
Short float
Float(single precision)
Float(8)
Long float
Float(double precision)
Char(length)
Character
Char(length)
Varchar(length)
Character varying length
Varchar(length)
Graph(length)
Graphic
Graphic(length)
Vargraph(length)
Varying graphic
Vargraphic(length)
Ucs2(length)
UCS-2
Graphic(length) with ccsid 13488 or ccsid 1200
Varucs2(length)
UCS-2
VarGraphic(length) with ccsid 13488 or ccsid 1200
Date or Date(format-separator)
Date
Date Datfmt(format) Datsep(separator)
Time or Time(format-separator)
Time
Time Timfmt(format) Timsep(separator)
Timestamp
Timestamp
Timestamp
DS
Data structure
Char
CLOB is not supported in RPG.
SQLTYPE keyword is used to declare CLOB in the RPG program
CLOB
DBCLOB is not supported in RPG.
SQLTYPE keyword is used to declare DBCLOB in the RPG program
DBCLOB
BLOB is not supported in RPG.
SQLTYPE keyword is used to declare BLOB in the RPG program
BLOB
BINARY is not supported in RPG.
SQLTYPE keyword is used to declare BINARY in the RPG program
BINARY
VARBINARY is not supported in RPG.
SQLTYPE keyword is used to declare VARBINARY in the RPG program
VARBINARY
XML is not supported in RPG.
SQLTYPE keyword is used to declare XML in the RPG program
XML
ROWID is not supported in RPG.
SQLTYPE keyword is used to declare ROWID in the RPG program
ROWID
Result Set Locator is not supported in RPG.
SQLTYPE keyword is used to declare the Result Set Locator in the RPG program
You can check for locks on a file/table using the system catalog view QSYS2.OBJ_LOCK. It can also be called as OBJECT_LOCK_INFO. You can embed the SQL query below in your sqlrpgle program and check for locks on a file/table. select count(*) from qsys2.object_lock_info where system_object_schema = 'TRead more
You can check for locks on a file/table using the system catalog view QSYS2.OBJ_LOCK. It can also be called as OBJECT_LOCK_INFO. You can embed the SQL query below in your sqlrpgle program and check for locks on a file/table.
select count(*) from qsys2.object_lock_info
where
system_object_schema = 'TESTLIB'
and system_object_name = 'TABLE1'
and object_type = '*FILE'
and lock_state = '*EXCL'
In the above SQL query, we are checking locks for files/tables Table1 in the library TESTLIB the important check here is the LOCK_STATE column. Since, when we run the program, it opens all the files and you might get shared locks which is fine for us we need to check for exclusive locks only what has been checked in the above SQL query. You can write the above SQL query in your RPG program like this:
DlockCnt S 10i 0 inz
/free
Exec Sql
select count(*) into :lockCnt from qsys2.object_lock_info
where
system_object_schema = 'TESTLIB'
and system_object_name = 'TABLE1'
and object_type = '*FILE'
and lock_state = '*EXCL';
If lockCnt > 0;
// Lock present on file/table
// Code to handle for Lock situation
dsply('Lock present on file');
return;
endif;
return;
/end-free
To test this code, you can put a lock on the file/table using the ALCOBJ command in one of your IBM i sessions and then you need to run this code on the same file from another session. ALCOBJ OBJ((TESTLIB/TABLE1 *FILE *EXCL))
Later, after your testing, you can remove the exclusive on that same file using the DLCOBJ command. DLCOBJ OBJ((TESTLIB/TABLE1 *FILE *EXCL))
You can use this SQL to replace the carriage return and line feed characters (X’0D25′) with spaces (X’4040′). update libname/filename set fieldname = replace(fieldname, X'0D25', X'4040') where fieldname like '%' concat X'0D25' concat '%' Note: Please take a backup of your file before running the updRead more
You can use this SQL to replace the carriage return and line feed characters (X’0D25′) with spaces (X’4040′).
update libname/filename
set fieldname = replace(fieldname, X'0D25', X'4040')
where fieldname like '%' concat X'0D25' concat '%'
Note: Please take a backup of your file before running the update to verify your results and in case any issue occurs you may then be able to restore your original file data.
the Save Results… option is by default disabled and you cannot download those results to an Excel spreadsheet by default because it only loads some rows at a time and you may have to press PAGE DOWN until you get all the data. This is a tedious task. You will see a message like 100 rows retrieved (mRead more
the Save Results… option is by default disabled and you cannot download those results to an Excel spreadsheet by default because it only loads some rows at a time and you may have to press PAGE DOWN until you get all the data. This is a tedious task. You will see a message like 100 rows retrieved (more data available) on the bottom left corner of the Run SQL Script screen. You can enable the Save Results… option in a few steps that allow you to download the SQL result in an Excel spreadsheet using ACS Run SQL Script.
Enable the Save Results… option that appears on Right-click on the SQL Result area which allows you to download data to Excel spreadsheets. For this, go to the Edit section in the top left corner click on that and that starts showing further options under the Edit section. Now click on the Preferences option under the Edit section. This will open the Preferences screen. Under the General Tab and below the New Connections heading check the Enable Saving of results option checkbox and click on Apply and OK.
It will prompt a dialog saying Preferences Saved. The settings for the current connection differ from those specified for new connections. Do you want to apply these settings on the current connection? Click on Yes.
Close the Run SQL script window and open it again. Run the SQL query again. That SQL query only fetched some rows of the table and more data is available to be loaded. So, please click on the little box in the bottom right corner of the Run SQL Script window to retrieve all rows.
Since you have reopened the Run SQL Script and also ran the SQL query you will now see a download option named Save Results… is enabled under the Right click menu on the results area.
Click on the Save Results… download option and download these SQL results as an Excel spreadsheet. Note: You can download results in other file formats as well such as .txt, .csv, .ods, .dsr, and tab-delimited text format.
Once you click OK, the Excel spreadsheet file is downloaded/saved to the specified location, and an Inquiry message dialog box appears mentioning file has been saved successfully Would you like to open it. Click Yes to open the downloaded Excel spreadsheet file from the ACS Run SQL Script utility.
We can extract the week from a YYYYMMDD formatted date using the week() function and substr() function. Please use the below SQL query to achieve this. select week(substr(char(datefield),1,4) concat '-' concat substr(char(datefield),5,2) concat '-' concat substr(char(datefield),7,2)) as weeknumber fRead more
We can extract the week from a YYYYMMDD formatted date using the week() function and substr() function. Please use the below SQL query to achieve this.
select week(substr(char(datefield),1,4) concat '-' concat
substr(char(datefield),5,2) concat '-' concat
substr(char(datefield),7,2)) as weeknumber
from libraryname/filename
or you can simply run the SQL query to test one of the values using a dummy table.
select week(substr(char(20240909),1,4) concat '-' concat
substr(char(20240909),5,2) concat '-' concat
substr(char(20240909),7,2)) as weeknumber
from sysibm.sysdummy1
Because there is no external description for system36 files. Thus, all of that data is contained in a single field when you access the file in SQL. Therefore, when you want to use SQL to access data from a system36 file you need to substring the data you want from the field. For Example, if the SystRead more
Because there is no external description for system36 files. Thus, all of that data is contained in a single field when you access the file in SQL. Therefore, when you want to use SQL to access data from a system36 file you need to substring the data you want from the field.
For Example, if the System36 file name is FILE1, and its single field is FLD1 then you can use the below SQL to get data from system36 files, You can change substring positions at your end as per your system36 file.
Select substr(fld1, 5, 4), substr(fld1,10,5) from FILE1
where substr(fld1,1,4) = 'A001'
Please note that you can get the field name of the system6 file by typing SQL select * from file1 and taking F4 to prompt the SQL query and then prompt the select fields.
How to call sql stored procedure with output parameter from within a cl program?
I have tried to call the SQL stored procedure with output parameter within a CL program using QZDFMDB2 to run SQL interactively in a CL program and I have succeeded a lot in that. Now, I can call the SQL stored procedure with the output parameter in the CL program, the only drawback that I face is IRead more
I have tried to
call
theSQL stored procedure with output parameter
within aCL program
usingQZDFMDB2
to run SQL interactively in a CL program and I have succeeded a lot in that. Now, I can call the SQL stored procedure with the output parameter in the CL program, the only drawback that I face is I am not getting the output parameter value returned in my CL program.To call the SQL stored procedure with output parameter in the CL program I have used the, so I created a
SQL variable
and passed that as areturn parameter
in the form of a command string to programQZDFMDB2
that allows to run SQL statements in CL program. This makes my first work done i.e.calling a SQL stored procedure in a CL program with output parameters
which earlier seemed very difficult or almost impossible. So congrats for this success that we have achieved so far.Now, the turn is for receiving the return value in the output parameter which is
SQL variable
here. So, it was sad but we are not getting return value from SQL stored procedure in our CL program. So, I decided to use some tricks and tweaks so that I would anyway receive the return value or value returned by the output parameterSQL stored procedure
in my CL program. Let me show you the code and steps that I followed to achieve this:SQL variable
using theCREATE VARIABLE
statement from STRSQL.In the SQL stored procedure code, a few lines are written intentionally such as we are writing
create or replace SQL variables
and setting their values as 1 or 0 according to SQL code value. Here, the SQL variable works as a return value for my CL program. Please note that SQL variable value is accessible to the same session in which its value is set by default during the create variable statement orSET
statement.RUNSQLSTM
command.CREATE VIEW
statement.Please, note that in
step 1
we created aSQL variable
namedOUT
in theTESTLIB
library so that we can later create a viewRTNVAL
inqtemp
library using that atstep 4
. For your knowledge as we have declared the viewrtnval
in my CL program so that I can populate that view with the value that was set by SQL stored procedure in SQL variable (SQL global variable
).At the beginning of the program, we create an SQL variable
out
intestlib
with a default blank value by passing the create or replace variable statement to theQZDFMDB2
program as a parameter in the string format.Then, we call the SQL stored procedure from within the CL program with input and output parameters by first building the
&cmd
string, and in, we pass theSQL variable
instead of any CL program variable. Then we pass it to theQZDFMDB2
program as a parameter to run the SQL stored procedure. Now till this point, we have not received any return value from the SQL stored procedure call usingQZDFMDB2
. However, within the SQL stored procedure script, we did set the respective success/failure value in the SQL variable globally and now I am ready to receive that in my CL program which would be the actual return value by my SQL stored procedure call.So, I selected the global SQL variable value and output it in a view named
rtnval
, and after that, I just read the view using theRCVF
command and evaluated the value from the view column&rtn
to the cl program variable&sqlout
. Therefore,&sqlout
would not contain the return value or the output parameter value that should be returned by the actual SQL stored procedure call within the CL program with the output parameterHow to use declare global temporary table statement in RPGLE?
Declare global temporary table statement defines a temporary table for the current session. The temporary table when declared then it is created in the work file database and its description is not populated in the system catalog files. This global temporary table cannot be shared with other sessionRead more
Declare global temporary table
statement defines a temporary table for the current session. The temporary table when declared then it is created in the work file database and its description is not populated in the system catalog files. This global temporary table cannot be shared with other sessions. Once the session ends, the global temporary table is dropped.Sample fully free sqlrpgle program to declare global temporary table.
Compiling and running this code will create a file GTM1 in the QTEMP library.
See lessselect * from qtemp.gtm1
How to call sql stored procedure in cl program?
We can call SQL stored procedure from within the CL program using the QZDFMDB2 program which is the datalink file manager DB2 CLP program present in the QSYS library. pgm dcl var(&cmd) type(*char) len(200) dcl var(&in1) type(*char) len(20) value('test') dcl var(&in2) type(*char) len(1) vRead more
We can call SQL stored procedure from within the CL program using the
QZDFMDB2
program which is thedatalink file manager DB2 CLP program
present in theQSYS
library.We need to build the command string which is the SQL stored procedure CALL statement with the required parameter. Later we pass that command string to the program
See lessqzdfmdb2
which executes SQL interactively from within the CL program.SQL0469 on calling a SQL procedure containing an INOUT parameter
When we call a SQL stored procedure using a constant value instead of a parameter marker (?) sqlcode -469 is returned. You can call a SQL stored procedure by passing a parameter marker in an INOUT parameter like this. call testlib.STORED33A('name1','M','?') However, you cannot even call using a paraRead more
When we
call
aSQL stored procedure
using aconstant value
instead of aparameter marker
(?)sqlcode -469
is returned.You can
call
aSQL stored procedure
by passing aparameter marker
in anINOUT parameter
like this.call testlib.STORED33A('name1','M','?')
However, you cannot even call using a parameters marker in the
STRSQL
session on an IBM i machine as theUse of parameter marker, NULL, or UNKNOWN is not valid
.However, You can call it by passing any value to the
OUT
orINOUT parameter
from theRun SQL script
likecall testlib.STORED33A('name1','M',NULL);
call testlib.STORED33A('name1','M',' ');
call testlib.STORED33A('name1','M',5);
call testlib.STORED33A('name1','M',?);
You will get the return output.
No such issue will occur when you call the
SQL stored procedure
from theRun SQL Script
. This issue will only occur in theSTRSQL
session. Therefore, to call it from theSTRSQL
session you first have to create aSQL global variable
usingCREATE VARIABLE
statement like below.The variableSQLOUT
was created intestlib
. It’s an*SRVPGM
object type of attributeCLE
.Now again try to call the
SQL stored procedure
from theSTRSQL
session on IBM i but this time passed theSQL global variable
for theOUT or INOUT parameter
in the procedure as below.CALL statement complete.
SQL7985
which means Call to procedureSTORED33A
completed successfully
.You can check the return value in the SQL global variable as follows:
the output return value in SQL global variable from SQL stored procedure call.
What are the equivalent SQL data types to ile rpg data types?
ILE RPG data types mapped to SQL data types: ILE RPG data type Description SQL data type DS Data structure Char Zoned(digits:decimal places) Zoned data Numeric(digits, decimal places) Packed(digits:decimal places) Packed data Decimal(digits, decimal places) Bindec(digits) 2-byte binary with 0 decimaRead more
ILE RPG data types mapped to SQL data types:
How to check for locks on a file or table using SQL?
You can check for locks on a file/table using the system catalog view QSYS2.OBJ_LOCK. It can also be called as OBJECT_LOCK_INFO. You can embed the SQL query below in your sqlrpgle program and check for locks on a file/table. select count(*) from qsys2.object_lock_info where system_object_schema = 'TRead more
You can check for locks on a file/table using the system catalog view
QSYS2.OBJ_LOCK
. It can also be called as OBJECT_LOCK_INFO. You can embed the SQL query below in your sqlrpgle program and check for locks on a file/table.In the above SQL query, we are checking locks for files/tables
Table1
in the libraryTESTLIB
the important check here is theLOCK_STATE
column. Since, when we run the program, it opens all the files and you might get shared locks which is fine for us we need to check forexclusive locks
only what has been checked in the above SQL query. You can write the above SQL query in your RPG program like this:To test this code, you can put a lock on the file/table using the
ALCOBJ
command in one of your IBM i sessions and then you need to run this code on the same file from another session.ALCOBJ OBJ((TESTLIB/TABLE1 *FILE *EXCL))
Later, after your testing, you can remove the exclusive on that same file using the
See lessDLCOBJ
command.DLCOBJ OBJ((TESTLIB/TABLE1 *FILE *EXCL))
how to replace hex values in a file field using SQL?
You can use this SQL to replace the carriage return and line feed characters (X’0D25′) with spaces (X’4040′). update libname/filename set fieldname = replace(fieldname, X'0D25', X'4040') where fieldname like '%' concat X'0D25' concat '%' Note: Please take a backup of your file before running the updRead more
You can use this SQL to replace the
carriage return
andline feed
characters (X’0D25′
) with spaces (X’4040′
).Note: Please take a backup of your file before running the update to verify your results and in case any issue occurs you may then be able to restore your original file data.
See lessCan i download the results as a file using the run sql script option on the ACS software?
the Save Results… option is by default disabled and you cannot download those results to an Excel spreadsheet by default because it only loads some rows at a time and you may have to press PAGE DOWN until you get all the data. This is a tedious task. You will see a message like 100 rows retrieved (mRead more
the
Save Results…
option isby default disabled
and you cannot download those results to an Excel spreadsheet by default because it only loads some rows at a time and you may have to pressPAGE DOWN
until you get all the data. This is a tedious task. You will see a message like100 rows retrieved (more data available)
on thebottom left corner
of theRun SQL Script
screen. You canenable
theSave Results…
option in a few steps that allow you todownload
theSQL result
in anExcel spreadsheet
using ACSRun SQL Script
.Enable
theSave Results…
option that appears on Right-click on the SQL Result area which allows you to download data to Excel spreadsheets. For this, go to theEdit
section in the top left corner click on that and that starts showing further options under theEdit
section. Now click on thePreferences
option under theEdit
section. This will open thePreferences
screen. Under theGeneral
Tab and below theNew Connections
heading check theEnable Saving of results
option checkbox and click onApply
andOK
.Preferences Saved. The settings for the current connection differ from those specified for new connections. Do you want to apply these settings on the current connection?
Click onYes
.Run SQL script
window and open it again. Run the SQL query again. That SQL query only fetched some rows of the table and more data is available to be loaded. So, please click on thelittle box in the bottom right corner
of theRun SQL Script
window to retrieve all rows.Run SQL Script
and also ran the SQL query you will now see a download option namedSave Results…
isenabled
under theRight click
menu on the results area.Save Results…
download option and download these SQL results as an Excel spreadsheet.Note: You can download results in other file formats as well such as
.txt
,.csv
,.ods
,.dsr
, andtab-delimited text format
.OK
, theExcel spreadsheet
file is downloaded/saved to the specified location, and an Inquiry message dialog box appears mentioningfile has been saved successfully Would you like to open it
. ClickYes
to open the downloaded Excel spreadsheet file from the ACS Run SQL Script utility.How can i derive the week from a YYYYMMDD formatted date?
We can extract the week from a YYYYMMDD formatted date using the week() function and substr() function. Please use the below SQL query to achieve this. select week(substr(char(datefield),1,4) concat '-' concat substr(char(datefield),5,2) concat '-' concat substr(char(datefield),7,2)) as weeknumber fRead more
We can
extract
theweek
from aYYYYMMDD
formatteddate
using theweek()
function andsubstr()
function. Please use the below SQL query to achieve this.or you can simply run the SQL query to test one of the values using a dummy table.
The output
See lessweek is 37
.How can i access system36 files using SQL?
Because there is no external description for system36 files. Thus, all of that data is contained in a single field when you access the file in SQL. Therefore, when you want to use SQL to access data from a system36 file you need to substring the data you want from the field. For Example, if the SystRead more
Because there is no external description for
system36
files. Thus, all of that data is contained in a single field when you access the file in SQL. Therefore, when you want to use SQL to access data from asystem36
file you need to substring the data you want from the field.For Example, if the
System36
file name isFILE1
, and its single field isFLD1
then you can use the below SQL to get data fromsystem36
files, You can change substring positions at your end as per yoursystem36
file.Select substr(fld1, 5, 4), substr(fld1,10,5) from FILE1
where substr(fld1,1,4) = 'A001'
Please note that you can get the field name of the system6 file by typing SQL
See lessselect * from file1
and takingF4
to prompt the SQL query and then prompt the select fields.