Modify the BTEQ script below for your environment. This script sends
the source code to the server to be compiled, but you may prefer to
compile it separately on the TPA node and then create the function
from the object code.
=== stat_dt.c ===
/*--------------------------------------------------------------------
** s t a t _ d t
** User-Defined Function to convert the first 4 timestamp bytes in
** DBC.TVFields.FieldStatistics to a date.
**
** 2005-05-02 G. Rommel -- initial release
**
**------------------------------------------------------------------*/
#define SQL_TEXT Latin_Text
#include <sqltypes_td.h>
#include <string.h>
void stat_dt (
VARBYTE *field_stats,
DATE *result,
char sqlstate[6] )
{
*result =
((((field_stats->bytes[1] * 256) + field_stats->bytes[0]) - 1900)
* 10000)
+ (field_stats->bytes[2] * 100) + field_stats->bytes[3];
strcpy(sqlstate, "00000");
return;
}
=== stat_dt.bteq ===
drop function sysdba.stat_dt;
create function sysdba.stat_dt
( varbyte(16400) )
returns date
language C
no sql
parameter style td_general
deterministic
returns null on null input
external name
'CS!stat_dt!/your/pathname/src/stat_dt.c!F!stat_dt';
.quit
|