PeopleTools Reference: Common Meta-SQL

PeopleTools Reference: Meta-SQL %Update
generates an update statement to change the database to match the values in the record object.


Example


Local Record &recJob;
&recJob.EMPLID.value = &emplid;
&recJob.EMPL_RCD.value = &empl_rcd;
SQLExec(“%SelectByKeyEffdt(:1)”, &recJob, %Date, &recJob);
&recJob.DEPTID.value = &deptid;
SQLExec(“%Update(:1)”, &recJob);




PeopleTools Reference: Meta-SQL %Delete
December 27, 2006 — digitaleagle 
generates a delete statement using the values from a record object


This command will pull the record name, the key fields, and the values for those key fields to generate the delete statement. This will result in the statement deleting one row from the database since the statement includes all of the keys for the record.


Example


Local Record &recJob;
&recJob.EMPLID.value = &emplid;
&recJob.EMPL_RCD.value = &empl_rcd;
&recJob.EFFDT.value = &effdt;
&recJob.EFFSEQ.value = 0;
SqlExec(“%Delete(:1)”, &recJob);


PeopleTools Reference: Meta-SQL %Insert
generates an Insert statement to insert the data from a record object into the database.


Remember that a record object (not a record definition) stores both the record structure (table name and field name) and the field values. Therefore, the system has everything it needs to write an insert statement: insert( … field list … ) values ( … options …).


Examples


Local Record &myRecord;
&myRecord.KEY1.value = “Key Value”;
&myRecord.FIELD1.value = “Field Value”;
SQLExec(“%Insert(:1)”, &myRecord);




PeopleTools Reference: Meta-SQL %SelectByKey
generates a select statement based on the given record definition.


Remember that a record object (not a record definition) stores both the record structure (table name and field name) and the field values. Therefore, the system has everything it needs to write a select statement: select … list of fields … from … table name … where … key field name … = … value for that field … and so on.


Related: %SelectByKeyEffdt


does the same thing except it adds the effective dating criteria to limit it to the most recent rows.


Examples


Local Record &recJob;
&recJob = CreateRecord(RECORD.JOB);
&recJob.EMPLID.value = &emplid;
&recJob.EMPL_RCD.value = &empl_rcd;
&recJob.EFFDT.value = &effdt;
&recJob.EFFSEQ.value = &effseq;
SqlExec(“%SelectByKey(:1)”, &recJob, &recJob);
WinMessage(“Job Code: ” | &recJob.JOBCODE.value);


Local Record &recNames, &recOutput;
&recNames = CreateRecord(RECORD.NAMES);
&recOutput = CreateRecord(RECORD.NAMES);
&recNames.EMPLID.value = &emplid;
&recNames.NAME_TYPE.value = “PRI”;
SqlExec(“%SelectByKeyEffdt(:1)”, &recNames, %Date, &recOutput);




PeopleTools Reference: Meta-SQL %SelectAll
Generates a select statement that selects all the fields from a chosen record.


Typically, when you use the %SelectAll, you would use a record object to store the results. That way you don’t have to know how many fields your result will return.


Examples


%SelectAll(JOB)


Local Record &myRecord;
&myRecord = CreateRecord(RECORD.MY_RECORD);
SQLExec(“%SelectAll(:1) WHERE MY_KEY = :2″, &myRecord, “My Key”, &myRecord);


Local Record &myInstallation;
&myRecord = CreateRecord(RECORD.INSTALLATION);
SQLExec(“%SelectAll(:1)”, &RECORD.INSTALLATION, &myInstallation);




PeopleTools Reference: Meta-SQL %Table
%Table


Replaces with the actual table name of the given record.


Generally, this just means adding a “PS_” to the front of the record name. But, PeopleTools actually checks the alternate table name from the Record Type tab to see if a value is there first.


Two Uses: 


Access a table with a reference or record object rather than embedding a table name in the SQL; PeopleTools will not index the table/record in a string literal. 
Reference the Temporary table in an App Engine; %Table is the only way to reference the table because the table name is assign dynamically at run time. 
Examples:


SELECT * FROM %Table(JOB) WHERE EMPLID = :1


SqlExec(“SELECT NAME FROM %Table(:1) WHERE EMPLID = :2″, Record.NAMES, &emplid, &name);


&sql = CreateSql(“SELECT * FROM %Table(:1) WHERE EMPLID = :2″, &MyRecord, &emplid);


INSERT INTO %Table(MYTEMP_TAO)
SELECT * FROM PS_MYDATATABLE


PeopleTools Reference: Meta-SQL DateIn/DateOut
December 27, 2006 — digitaleagle 
DateIn


Description


Converts a date into the form the database uses.
Used for: 


Where clauses 
Insert/Update 
Remember DateIn passes a date into the database.


DateOut


Description


Converts a date into the form that PeopleTools uses.
Used for: 


Select clause 
Examples


SELECT %DateOut(MAX(EFFDT))
FROM PS_JOB
WHERE EMPLID = :1
AND EMPL_RCD = :2
AND EFFDT 


INSERT INTO PS_MY_RNCTL(OPRID, RUN_CONTROL_ID, AS_OF_DATE)
VALUES(:1, :2, %DateIn(:3))


UPDATE PS_MY_TABLE
SET MY_DATE = %DateIn(:1)
WHERE MY_DATE

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值