Exporting Dates to CSV - export-to-csv

I can't figure out why the result of the export ( as csv ) has the forward slashes removed when viewing in excel. This options seems to work but the resulting data shows dates like this ' 2 21 1991 7 26 1989 '
exporterFieldCallback: function (grid, row, col, input) {
if (col.colDef.type == 'date')
input = $filter('date')(input, 'MM/dd/yyyy');
return input;
},
Please let me know what I am missing here
http://plnkr.co/edit/iJRhjy0nXR4P1xVVDRZd?p=preview

There may be a better way to do this, but it seems that since it was date format excel pigeonholed it into a date format which didn't include the format I was trying to display.
I made 1 change to make this work: adding single space around the field to force it to be a general field.
exporterFieldCallback: function (grid, row, col, input) {
if (col.colDef.type == 'date')
input = ' '+$filter('date')(input, 'MM/dd/yyyy') +' ' ;
},

Related

FOR XML PATH in Postgres

Hi everyone I'm trying convert this code so it works in postgres. I figured I will use to_char(dateinquar:: date, 'mm/dd/yyyy') instead of convert(varchar,dateinquar,101). But I'm not sure what can be used instead of FOR XML PATH? I don't need to generate any XML document. How would I get multiple dates in a single row separated by comma for the case below?
Case d.Closing WHEN 0 THEN NULL WHEN 1 THEN (
substring((SELECT convert(varchar,dateinquar,101) + ', ' FROM PDT_tblAReasons sub
WHERE sub.IDnumber = d.IDnumber and dateoutquar IS NULL
GROUP BY IDnumber,dateinquar FOR XML PATH('')),0,len((
SELECT convert(varchar,dateinquar,101) + ', ' FROM PDT_tblAReasons sub
WHERE sub.IDnumber = d.IDnumber and dateoutquar IS NULL
GROUP BY IDnumber,dateinquar FOR XML PATH('')))-0)) end As [Closing Date]
Thank you

Postgres: Retrieve first n words from column

I know that I can do a text search in Postgres with TextSearch and get some result with
select ts_headline('german',content, tq, 'MaxFragments=4, MinWords=5, MaxWords=12,
ShortWord=3, StartSel = <strong>, StopSel = </strong>') as highlight, ...
FROM to_tsquery('german', 'test') tq ...
Is there a similar way to apply to content the same limitations? i.e. to get directly up to 12 words from the column content.
You could use regular expressions:
SELECT (regexp_match(
regexp_replace(content, '[^\w\s]+', ' ', 'g'),
'^\s*((?:\w+\s+){9}\w+)'
))[1] FROM ...
That will first replace everything that is not a space or alphanumerical character with a space and then return the first 10 words.

PostreSQL- How to convert float containing a number of seconds to MM:SS.sss

I have a float8 that contains a number of seconds ie 65.455. I was trying to format a column in a view so that it would read as 1:05.455.
Using postgres command like this:
TO_CHAR((user_data.totaltime || ' second')::interval, 'MI:SS')
I can format it as 1:05 but i loose the precision i need.
Anyone know of a way to achieve what i need ? It doesn't look like interval allows the formatting of milliseconds.
Try justify_interval:
SELECT justify_interval(
CAST(65.455::text || ' seconds' AS interval)
);
Here is a rather brute force you may do this, using the base string functions:
SELECT
FLOOR(65.455 / 60)::text || ':' || LPAD(FLOOR(65.455 % 60)::text, 2, '0') ||
TRIM(LEADING '0' FROM (65.455 % 1)::text);
This outputs:
1:05.455
Demo

# in Caché between columns

I have a SQL query and I would like to insert a hashtag between one column and another to be able to reference in Excel, using an import option in fields delimited by #. Anyone have an idea how to do it? A query is as follows:
SELECT FC.folha, folha->folhames,folha->folhaano, folha->folhaseq, folha->folhadesc, folha->TipoCod as Tipo_Folha,
folha->FolhaFechFormatado as Folha_Fechada, folha->DataPagamentoFormatada as Data_Pgto,
Servidor->matricula, Servidor->nome, FC.rubrica,
FC.Rubrica->Codigo, FC.Rubrica->Descricao, FC.fator, FC.TipoRubricaFormatado as TipoRubrica,
FC.ValorFormatado,FC.ParcelaAtual, FC.ParcelaTotal
FROM RHFolCalculo FC WHERE folha -> FolhaFech = 1
AND folha->folhaano = 2018
and folha->folhames = 06
and folha->TipoCod->codigo in (1,2,3,4,6,9)
You are generating delimited output from the query, so the first row should be a header row, with all following rows the data rows. You will really only have one column due to concat. So remove the alias from the columns, output the first row like so (using the alias here) . . .
SELECT 'folha#folhames#folhaano#folhaseq#folhadesc#Tipo_Folha#
Folha_Fechada#Data_Pgto#
matricula#nome#rubrica#
Codigo#Descricao#fator#TipoRubrica#
ValorFormatado#ParcelaAtual#ParcelaTotal'
UNION
SELECT FC.folha || '#' || folha->folhames || '#' || folha->folhaano . . .
The UNION will give the remaining rows. Note some conversion may be necessary on the columns data if not all strings.

How to make a function in DB2 database to convert an integer to date, and the case when is 0?

I was trying to make a function to work in db2:
CREATE FUNCTION TO_DATE8(DATE_STRING numeric(8,0))
RETURNS DATE
LANGUAGE SQL
IF DATE_STRING > 0 THEN
// ERROR ->
RETURN DATE ( TO_DATE ( SUBSTR ( DATE_STRING , 1 , 8 ) , 'YYYYMMDD' ) )
ELSE
RETURN DATE ( TO_DATE ( '00000000' , 'YYYYMMDD' ) )
END IF
END
ERROR: DATE IS NOT VALID
What to do?
The form of the procedure required seems to be like this (at least on the iSeries version):
CREATE FUNCTION TO_DATE8(DATE_STRING numeric(8,0))
RETURNS DATE
LANGUAGE SQL
BEGIN
RETURN(CASE WHEN DATE_STRING > 0 THEN DATE(SUBSTR(DATE_STRING, 1, 4) || '-' ||
SUBSTR(DATE_STRING, 5, 2) || '-' ||
SUBSTR(DATE_STRING, 7, 2))
ELSE DATE('0001-01-01')
END);
END
However:
Your procedure is misnamed (reading from a date-8, not to it).
Your DATE_STRING is not a string (or even a char), it's numeric. Please rename it to something that does not include the datatype (dateToConvert works)
You seem to want to return something that is not a valid date (all 0s). I'm returning *loval here, although it's possible it should actually be null.
I didn't put in enough checks for a valid date - this will blow up really easily.
If at all possible, the database should be changed to contain actual dates, not a numeric value. Disk is (relative to programmer/architect headaches) cheap.
You may also find a calendar file helpful, if the 8-digit numeric was one of the included columns.
For the benifit of others, this can be done in one line rather than a function:
CASE WHEN MYDATE = 0 THEN NULL ELSE DATE(INSERT(INSERT(LEFT(CHAR(MYDATE),8),5,0,'-'),8,0,'-')) END
MYDATE was 8 packed in my case.