How to do columns formatting in psql script - psql

ooking for equivalent command in psql for the below sqlplus commands
column IC format A9
column BCO format A9
column InvNo format A14
column InvDt format A12
column CustNo format A10
column CustName format A15
column Amount format 999,999,999.00
column Curr format A6
column TransAmt format 999,999,999.00
column BillSched format 999999
column BillSchedDT format A12
column Error format A40
column ErrorValue format A30
file name:sqlBillingErrorQ.sql

Related

Google Sheets vlookup cannot find value error on date match

I have two sheets ('Car' and 'Gas Data') in a google sheets document.
Each has dates in column A. When I add a new date in a row in 'Car', a want to autofill the value in column D from the sheet 'Gas Data' with the matching date row.
My failing vlookup: =VLOOKUP(A2,'Ohio Gas Data'!A:D,4,FALSE)
I am getting the error: "Did not find value '44352' in VLOOKUP evaluation." but the value in A2 is a date and I have formatted both columns for dates.
How can I edit the above vlookup to select A2 in 'Car', match it with a date in column A of 'Gas Data', then select the value from Column D?
You may try with this. Even if it's a text or a date with time (meaning that instead of 44352 you have 44352.6012 for example), you can try with:
=XLOOKUP(DATEVALUE(A2),INDEX(DATEVALUE('Ohio Gas Data'!A:A)),'Ohio Gas Data'!D:D,"No match",0)
It should round or convert both the column and the value in A2 to make them match. I added an option of "No match" so you have the "feedback"
Let me know!

Google Sheets: by the last non-empty cell in column, return the value in corresponding cell in another column?

 Hello!
 So I have dates in Column A (A3:A). And I have transactions (formatted as currency) in Column C (C3:C). So I want a cell D3 in Column D to show the date (preferably only month but it is not vital) of the last transaction.
 In other words I need a formula that would check the whole Column C, find the last transaction (assuming that there will be blank cells in that column), find the corresponding date in Column A (date when transaction occured) and return that value (date) in cell D3 of Column D.
 INDEX? MATCH? HLOOKUP?
 Please advise.
Column A Column C Column D
3 01/01/2021            10.98                       01/05/2021
4 01/02/2021            15.64
5 01/03/2021
6 01/04/2021
7 01/05/2021            20.93
8 01/05/2021            76.28
Try
=+sort(A:A, row(A:A)*(C:C<>""),)
or
=INDEX(A:A, MATCH(2, IF(C:C<>"", 1), 1))
or even
=lookup(9^9, C:C, A:A)
and see if that works?

Filter function and ignoring a condition

I used the following formula to filter a date range between the date entered in A3 and date entered in B3 and also the data entered in C3 that matches column D
=Filter('Sort Violations'!P2:P,'Sort Violations'!C2:C>=Int(A3),'Sort Violations'!C2:C<=Int(B3),'Sort Violations'!D2:D=C3)
I'd like the formula to work where if C3 is empty/blank, the filter still pulls all data from the other conditions in the filter (date range). I think it needs a len in the formula but I'm not sure how...
try this if it works for you:
=IF(LEN(C3), FILTER('Sort Violations'!P2:P, 'Sort Violations'!C2:C>=INT(A3),
'Sort Violations'!C2:C<=INT(B3),
'Sort Violations'!D2:D=C3), )

Google Sheets QUERY returning wrong values using >date

Note: Australian date format (DD/MM/YYYY) below.
I have the following formula on Sheet2:
=QUERY ('Sheet1'!$A:$B, "select B where (A>date'"&text ($C$3, "yyyy-MM-dd")&"')", 0)
The source data on Sheet1 ($A:$B) looks like:
26/05/2015 A1
26/05/2015 A2
26/05/2015 A3
10/11/2015 A4
02/01/2015 A5
21/07/2015 A6
24/12/2015 A7
24/12/2015 A8
25/12/2015 A9
27/08/2015 A10
The value stored in $C$3 on sheet2 is manually entered, but is currently set to "01/12/2015".
When I run the query it returns me with these values in my data set
10/11/2015
02/01/2015
21/07/2015
24/12/2015
24/12/2015
25/12/2015
27/08/2015
Why is the greater than not working for my dates?
e.g. I'm asking the query to give me all dates that occur after the 01/12/2015, but am receiving dates before then (even if the dates were doing something funny with the AU/US date format, it still doesn't make sense).
A FILTER formula may work instead:
=FILTER(Sheet1!B:B,Sheet1!A:A>C3)

Formatting: Changing Column Headers for SqlPlus Query

I'm having trouble with two formatting issues that I would really appreciate help with:
1) The Days Open column is displaying the number of days properly, but the column name is being overwritten by my conversion command, and
2) I need the Order Date (OOpenDate) to be displayed in the "MM/DD/YYYY" format
Code:
column O_Num heading 'Order|Number' format a6
column OOpenDate heading 'Order|Date' format a10
column (sysdate-OrderOpenDate) heading 'Days|Open' format a4
select O_Num, OOpenDate, to_char(sysdate-OOpenDate, '999')
from Orders
where Status = 'Open';
What its currently displaying:
Order Order
Number Date TO_C
------ --------- ------
100 03-DEC-13 14
What I want it to display as:
Order Order Days
Number Date Open
------ --------- ------
100 12/03/2013 14
Thank you in advance!
The simplest approach would be to alias the "Days Open" column and apply the format mask to the alias
column days_open heading 'Days|Open' format a4;
select O_Num, OOpenDate, to_char(sysdate-OOpenDate, '999') days_open
from Orders
where Status = 'Open';
Otherwise, the column name in your column command would need to exactly match the expression in your SELECT statement (including the to_char, any spaces, etc.) That's possible but it generally makes things rather hard to maintain.

Resources