简体   繁体   中英

QlikView Convert 1753-01-01 00:00:00.000 to NULL

I am trying to convert data from SQL as 1753-01-01 00:00:00.000 to be shown as NULL values in QlikView.

I do the following in the QlikView Load statements -

SET NullTimeStamp   = if ($1 = '1753-01-01 00:00:00', null(), $1);
Then use it when LOAD:

LOAD

$(NullTimeStamp(YourDateField1)) AS YOURDATEFIELD1,

$(NullTimeStamp(YourDateField2)) AS YOURDATEFIELD2,

$(NullTimeStamp(YourDateField3)) AS YOURDATEFIELD3

However, I have many fields with Time and Dates in my tables so I was wondering if there is a more elegant way of solving this issue?

Ive done something similar in the past. The idea is to generate part of the load script in a variable and then use this variable as part of the next load script

DummyData:
Load * Inline [
Something1             , Something2, Something3, Something4, Something5
1753-01-01 00:00:00.000,          2,          3,          4, 1753-01-01 00:00:00.000
];

SET NullTimeStamp   = if ($1 = '1753-01-01 00:00:00', null(), $1);

// Define a temp table
// that holds list of fields that have to be checked with NullTimeStamp
Fields:
Load * Inline [
FieldNames 
Something1
Something2
Something3
Something4
Something5
];

let FieldsConcatenation = '';

// loop through the NullTimeStamp-ed fields
for a = 1 to NoOfRows('Fields')
  let f = FieldValue('FieldNames', a);

  // concatenate each iteration to form part of the RealLoad table script
  let FieldsConcatenation = '$(FieldsConcatenation)' &  '$(NullTimeStamp('  &  '$(f)' & ')) as ' & Upper('$(f)') & ',' & chr(13);

next

// remove the last comma
let FieldsConcatenation = left('$(FieldsConcatenation)', Index('$(FieldsConcatenation)', ',' , -1) -1);

// we dont need this anymore
Drop Table Fields;

// add FieldsConcatenation variable as part of the load script
RealLoad:
Load
  $(FieldsConcatenation),
  'a' as LoadTheRestHere
Resident
  DummyData;

// we dont need this anymore 
Drop Table DummyData;

FieldsConcatenation variable will have the following content: 可变内容

The original table: 原表

And the final table: 决赛桌

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM