I was wondering if it was possible to use the datetime module in python to create day-specific tables so that the table's name is the date itself.
date_object = datetime.date.today()
sqlite_create_transfer_table = '''CREATE TABLE IF NOT EXISTS date_object (
sender TEXT NOT NULL,
recipient TEXT NOT NULL,
ID text NOT NULL,
Size NOT NULL,
Colour NOT NULL,
Quantity INTEGER NOT NULL);'''
However this just makes the table titled 'date_object' rather than using the variable. Any help would be greatly appreciated, thanks! <3
datetime.date.today() will return a datetime.date object which you must convert to a string, but even then a string like 2022-03-05 is not a valid name for SQLite.
You must enclose it between square brackets or backticks or double quotes.
Try this:
date_object = datetime.date.today()
sqlite_create_transfer_table = f"""CREATE TABLE IF NOT EXISTS [%s](
sender TEXT NOT NULL,
recipient TEXT NOT NULL,
ID text NOT NULL,
Size NOT NULL,
Colour NOT NULL,
Quantity INTEGER NOT NULL);""" % date_object
You need to concatenate the query something like this:
sqlite_create_transfer_table = '''CREATE TABLE IF NOT EXISTS '+date_object+' (
sender TEXT NOT NULL,
recipient TEXT NOT NULL,
ID text NOT NULL,
Size NOT NULL,
Colour NOT NULL,
Quantity INTEGER NOT NULL);'''
Related
when I try to download a table with grouping by fields, it does not appear correctly in the pdf, can anyone help me?
รง
Are you referring to the null values appearing in the output. If so then you can use an accessor on the column definitions to convert the null value into an empty string so it renders correctly.
To start with we define an accessor function outside of Tabulator:
var nullFixingAccessor = function(value){
return value === null ? "" : value; //return value or empty string if it is null
}
Then in each column definition for a column that might contain a null we set it on the accessorDownload property:
{title:"Act", field:"act", accessorDownload:nullFixingAccessor},
This will then convert the null values to an empty string when the pdf is downloaded
do you know how to remove a text between two words in notepad ++
VALUES (1, NULL, NULL,
VALUES (2, NULL, NULL,
VALUES (3, NULL, NULL,
to
VALUES (NULL, NULL,
If you just want to remove the first entry from each VALUES clause, then try the following find and replace, in regex mode:
Find: VALUES \([^,]+,\s*
Replace: VALUES (
Check the demo link below to a working example.
Demo
Ctrl+H
Find what: VALUES \(\K[^,]+, ?
Replace with: LEAVE EMPTY
check Wrap around
check Regular expression
Replace all
Explanation:
VALUES \( # literally
\K # forget all we have seen until this position
[^,]+ # 1 or more not comma
, ? # a comma followed by an optional space
Result for given example:
VALUES (NULL, NULL,
VALUES (NULL, NULL,
VALUES (NULL, NULL,
Screen capture:
resolved
VALUES.*?NULL
VALUES\(NULL
To query empty fields I have seen this answer:
Postgresql, select empty fields
(unfortunately I don't have enough reputation points to answer #wildplasser on that post, so here we go)
Wildplasser's answer:
SELECT mystr, mystr1
FROM mytable
WHERE COALESCE(mystr, '') = ''
OR COALESCE(mystr1, '') = ''
;
I am not sure I get the COALESCE method, but it also works for me this way (specific for my string data type):
SELECT mystr, mystr1
FROM mytable
WHERE mystr = '' ;
My questions are:
Does COALESCE work for any data type?
Is there any better way to query empty strings? i.e., column_value = ' '
First you need to understand the difference between NULL and "empty".
NULL is the absence of a value. Any (or at least almost any) data type can be NULL. When you have a column of type integer, and you don't want to put a value in that field, you put NULL.
"Empty" is a string/text concept. It's a string with an empty value, i.e. ''. A text field with an empty string contains a value: the empty string. It is not the same as containing NULL, i.e. no value. Other data types e.g. integer, boolean, json, whatever, can't have an empty string.
Now to COALESCE. That function works on any data type, and basically it returns the first not-NULL result of its arguments. So COALESCE(NULL, TRUE) returns TRUE because the first argument is NULL; COALESCE(FALSE, TRUE) returns FALSE because the first argument is not NULL; and COALESCE(NULL, NULL) returns NULL because there are no not-NULL arguments.
So, COALESCE(field, '') returns the value of field if it's not NULL, and otherwise returns an empty string. When used in COALESCE(field, '') = '' when trying to find any rows where field is "empty", this is basically saying "if field is NULL then use an empty string in its place, then see if it equals an empty string". This is because NULL and an empty string are not equivalent, and "you" are trying to find any rows where fields are NULL or empty.
In your version of the query, where you just do field = '', that will ONLY return results where field is actually an empty string, not where field is NULL. Which behaviour you desire is up to you.
With COALESCE you will get NULL values too in the first query.
1- In Postgresql, you can't mix datatype example here, but you can use the function to_char to mix values
2- I don't understand your question
I think based on the definition of coalesce itself as
"The COALESCE() function returns the first non-null value in a list."
means that it work for any data type
I don't really understand the question but i think yes its already the most efficient way to make empty string
In my report I have the field set to numeric, but when I export it to Excel, if the field is 0, it changes to a text field and fills it with 0.0000000000000000000000. If it's not 0, it comes across as numeric. I've tried checking for NULL, but it truly has 0 in it. I've also tried FORMATNUMBER with no luck. This is one of the combinations I've tried. If it's in US dollars, they want a dollar sign:
=IIF(Fields!Unit.Value = "USD", FORMATCURRENCY(Fields!JanActive.Value,2),FORMATNUMBER(Fields!JanActive.Value,2))
This was making me crazy until I realized that I needed the Value expression to work with the Format expression. Here's what fixed it:
Value expression
=IIF(Fields!JanActive.Value = 0, 0.0, Fields!JanActive.value)
Format expression
=IIF(Fields!Unit.Value = "USD", "'$'#,0.00;('$'#,0.00)", "#0.##")
Not sure what would happen if the value is NULL, but I think that could be addressed in the value expression.
I need to import certain information from an Excel file into an Access DB and in order to do this, I am using DAO.
The user gets the excel source file from a system, he does not need to directly interact with it. This source file has 10 columns and I would need to retrieve only certain records from it.
I am using this to retrieve all the records:
Set destinationFile = CurrentDb
Set dbtmp = OpenDatabase(sourceFile, False, True, "Excel 8.0;")
DoEvents
Set rs = dbtmp.OpenRecordset("SELECT * FROM [EEX_Avail_Cap_ALL_DEU_D1_S_Y1$A1:J65536]")
My problem comes when I want to retrieve only certain records using a WHERE clause. The name of the field where I want to apply the clause is 'Date (UCT)' (remember that the user gets this source file from another system) and I can not get the WHERE clause to work on it. If I apply the WHERE clause on another field, whose name does not have ( ) or spaces, then it works. Example:
Set rs = dbtmp.OpenRecordset("SELECT * FROM [EEX_Avail_Cap_ALL_DEU_D1_S_Y1$A1:J65536] WHERE Other = 12925")
The previous instruction will retrieve only the number of records where the field Other has the value 12925.
Could anyone please tell me how can I achieve the same result but with a field name that has spaces and parenthesis i.e. 'Date (UCT)' ?
Thank you very much.
Octavio
Try enclosing the field name in square brackets:
SELECT * FROM [EEX_Avail_Cap_ALL_DEU_D1_S_Y1$A1:J65536] WHERE [Date (UCT)] = 12925
or if it's a date we are looking for:
SELECT * FROM [EEX_Avail_Cap_ALL_DEU_D1_S_Y1$A1:J65536] WHERE [Date (UCT)] = #02/14/13#;
To use date literal you must enclose it in # characters and write the date in MM/DD/YY format regardless of any regional settings on your machine