How to get access field property in visual basic 2017 - ms-access

For my program I want to use accdb database, created with Access 2016. Now I want to set the textboxes and such so that it will have the same length and property (short text, long text, number or so) as the datafield has.
Is there a way to get this kind of info in visual basic 2017? the table and row name are both known.
I have search the internet, but can't find any information about this. The only thing I saw was schema info, but this I don't understand exactly.
Thanks,
Hans

Query the Type property of the Field object, e.g.:
CurrentDb.TableDefs("YourTable").Fields("YourField").Type
This will return one of the following enumerations:
+-------------------+--------------------------+
| Constant | Description |
+-------------------+--------------------------+
| 16 | dbBigInt | Big Integer |
| 9 | dbBinary | Binary |
| 1 | dbBoolean | Boolean |
| 2 | dbByte | Byte |
| 18 | dbChar | Char |
| 5 | dbCurrency | Currency |
| 8 | dbDate | Date/Time |
| 20 | dbDecimal | Decimal |
| 7 | dbDouble | Double |
| 21 | dbFloat | Float |
| 15 | dbGUID | GUID |
| 3 | dbInteger | Integer |
| 4 | dbLong | Long |
| 11 | dbLongBinary | Long Binary (OLE Object) |
| 12 | dbMemo | Memo |
| 19 | dbNumeric | Numeric |
| 6 | dbSingle | Single |
| 10 | dbText | Text |
| 22 | dbTime | Time |
| 23 | dbTimeStamp | Time Stamp |
| 17 | dbVarBinary | VarBinary |
+----+--------------+--------------------------+

Related

Mysql table records are displayed in a crooked manner

I have created a table in MySQL but when I display the table, some records are displayed in a crooked manner.
Here's the table displayed:
select * from air_passenger_profile;
+------------+----------+------------+-----------+---------------------------------+---------------+---------------------+
| profile_id | password | first_name | last_name | address | mobile_number | email_id |
+------------+----------+------------+-----------+---------------------------------+---------------+---------------------+
| PFL001 | PFL001 | LATHA | SANKAR | 123 BROAD CROSS ST,CHENNAI-48 | 9876543210 | LATHA#GMAIL.COM |
| PFL002 | PFL002 | ARUN | PRAKASH | 768 2ND STREET,BENGALURU-20 | 8094564243 | ARUN#AOL.COM |
| PFL003 | PFL003 | AMIT | VIKARAM | 43 5TH STREET,KOCHI-84 | 9497996990 | AMIT#AOL.COM |
| PFL004 | PFL004 | AARTHI | RAMESH | 343 6TH STREET,HYDERABAD-76 | 9595652530 | AARTHI#GMAIL.COM |
| PFL005 | PFL005 | SIVA | KUMAR | 125 8TH STREET,CHENNAI-46 | 9884416986 | SIVA#GMAIL.COM |
| PFL006 | PFL006 | RAMESH | BABU | 109 2ND CROSS ST,KOCHI-12 | 9432198760 | RAMESH#GMAIL.COM |
| PFL007 | PFL007 | GAYATHRI | RAGHU | 23 2ND CROSS ST,BENGALURU-12 | 8073245678 | GAYATHRI#GMAIL.COM |
| PFL008 | PFL008 | GANESH | KANNAN | 45 3RD ST,HYDERABAD-21 | 9375237890 | GANESH#GMAIL.COM |
+------------+----------+------------+-----------+---------------------------------+---------------+---------------------+
You place it into your database with spaces. At the point where you insert your variables into the databse, you could use PHP's trim() function, or MySQL's, to store it without the spaces.
To correct your current values:
UPDATE air_passenger_profile SET first_name = TRIM(first_name), etc...

How to get the sum of previous 10 rows in mysql?

Is it possible to get the sum of values in last 10 rows with respect to the current row?
I have created a database for a shop, which contains a table named purchase_details. Structure of that table is:
+--------------------------------+---------------+-----+
| Field | Type | Key |
+--------------------------------+---------------+-----+
| Trans_ID | int(11) | PRI |
| Dealer_Name | varchar(40) | |
| Todays_Purchase | double(18,10) | |
| Total_Purchase_In_Last_10_Days | double(18,10) | |
+--------------------------------+---------------+-----+
Sample data:
+----------+-------------+-----------------+--------------------------------+
| Trans_ID | Dealer_Name | Todays_Purchase | Total_Purchase_In_Last_10_Days |
+----------+-------------+-----------------+--------------------------------+
| 1 | Rahul | 7769.1488285639 | NULL |
| 2 | Rahul | 4158.5117578537 | NULL |
| 3 | Rahul | 7200.1363099802 | NULL |
| 4 | Rahul | 9338.8341269511 | NULL |
| 5 | Rahul | 5897.7252866370 | NULL |
| 6 | Rahul | 3266.6656585172 | NULL |
| 7 | Rahul | 3188.0742696276 | NULL |
| 8 | Rahul | 4270.5917314234 | NULL |
| 9 | Rahul | 2604.3369713541 | NULL |
| 10 | Rahul | 7908.6014441989 | NULL |
| 11 | Rahul | 2693.4584823737 | NULL |
| 12 | Rahul | 7945.7825034862 | NULL |
| 13 | Rahul | 1904.1472157570 | NULL |
| 14 | Rajesh | 7093.0478540344 | NULL |
| 15 | Rajesh | 3219.3736989638 | NULL |
+----------+-------------+-----------------+--------------------------------+
I want get the sum of purchases done in last 10 transactions, with the condition that there should be at least 10 transactions to sum up.
Expected output:
+----------+-------------+-----------------+--------------------------------+
| Trans_ID | Dealer_Name | Todays_Purchase | Total_Purchase_In_Last_10_Days |
+----------+-------------+-----------------+--------------------------------+
| 1 | Rahul | 7769.1488285639 | 0.0000000000 |
| 2 | Rahul | 4158.5117578537 | 0.0000000000 |
| 3 | Rahul | 7200.1363099802 | 0.0000000000 |
| 4 | Rahul | 9338.8341269511 | 0.0000000000 |
| 5 | Rahul | 5897.7252866370 | 0.0000000000 |
| 6 | Rahul | 3266.6656585172 | 0.0000000000 |
| 7 | Rahul | 3188.0742696276 | 0.0000000000 |
| 8 | Rahul | 4270.5917314234 | 0.0000000000 |
| 9 | Rahul | 2604.3369713541 | 0.0000000000 |
| 10 | Rahul | 7908.6014441989 | 55602.6263900000 |
| 11 | Rahul | 2693.4584823737 | 50526.9360400000 |
| 12 | Rahul | 7945.7825034862 | 54314.2067800000 |
| 13 | Rahul | 1904.1472157570 | 49018.2176900000 |
| 14 | Rajesh | 7093.0478540344 | 0.0000000000 |
| 15 | Rajesh | 3219.3736989638 | 0.0000000000 |
+----------+-------------+-----------------+--------------------------------+
For this, I've created a mysql function, which will take the Trans_ID and Dealer_Name as a parameter, and will return the sum of Todays_Purchase column.
Function definition:
CREATE FUNCTION GET_TOTAL_PURCHASE(paramTransID INT, paramDealerName VARCHAR(40))
RETURNS DOUBLE(18,10)
READS SQL DATA
BEGIN
DECLARE totalPurchase DOUBLE(18,10);
SET totalPurchase = 0;
SELECT SUM(Todays_Purchase)
INTO totalPurchase
FROM purchase_details
WHERE Trans_ID > (paramTransID-10)
AND Trans_ID <= paramTransID
AND Dealer_Name = paramDealerName;
RETURN totalPurchase;
END
And the SQL query to update Total_Purchase_In_Last_10_Days column is:
UPDATE purchase_details
SET Total_Purchase_In_Last_10_Days = GET_TOTAL_PURCHASE(Trans_ID, Dealer_Name);
Above SQL works properly, but it takes too much time to execute. There are more than a million records in the table, so the query takes more than 5 minutes. Hoe to improve this?
Derived information (such as what you are asking for) is properly done in SELECTs, not by having redundant code in the table.
If one user pulls up his info, it will be reasonably cheap to compute the sum on the fly. And you already have the FUNCTION to do that.
However, can you really trust Trans_ID to be consecutive, no gaps, etc? Your nomenclature is inconsistent: "_Last_10_Days" vs "previous 10 rows" versus "Trans_". "10 days" can be tricky if there are gaps. Etc.

how to convert values in a set/Enum into integers mysql

I have a database with this table(rating)..
+---------+-------------+----------+------+------------+
| rate_id | reviewer_id | movie_id | rate | date1 |
+---------+-------------+----------+------+------------+
| 1 | 201 | 101 | 2 | 2011-01-22 |
| 2 | 201 | 101 | 4 | 2011-01-27 |
| 3 | 202 | 106 | 4 | NULL |
| 4 | 203 | 103 | 2 | 2011-01-20 |
| 5 | 203 | 108 | 4 | 2011-01-12 |
| 6 | 203 | 108 | 2 | 2011-01-30 |
| 7 | 204 | 101 | 3 | 2011-01-09 |
| 8 | 205 | 103 | 3 | 2011-01-27 |
| 9 | 205 | 104 | 2 | 2011-01-22 |
| 10 | 205 | 108 | 4 | NULL |
| 11 | 206 | 107 | 3 | 2011-01-15 |
| 12 | 206 | 106 | 5 | 2011-01-19 |
| 13 | 207 | 107 | 5 | 2011-01-20 |
| 14 | 208 | 104 | 3 | 2011-01-02 |
+---------+-------------+----------+------+------------+
the rate is a set which has those values
('1','2','3','4','5'). i want to convert this set values to integers. i used cast(rate as unsigned) .then i used this query..
SELECT rate,cast(rate AS UNSIGNED) FROM rating;
it gives me this table
mysql> SELECT rate,cast(rate as unsigned) FROM rating;
+------+------------------------+
| rate | cast(rate as unsigned) |
+------+------------------------+
| 2 | 2 |
| 4 | 8 |
| 4 | 8 |
| 2 | 2 |
| 4 | 8 |
| 2 | 2 |
| 3 | 4 |
| 3 | 4 |
| 2 | 2 |
| 4 | 8 |
| 3 | 4 |
| 5 | 16 |
| 5 | 16 |
| 3 | 4 |
+------+------------------------+
it looks like binary values..plz help me to convert this into correct integer values..
Try this..
CAST (CAST(rate AS char) AS UNSIGNED);
it works..
ENUM is not a good selection for number values. instead of using ENUM you can use TYNYINT and filter values for only accept [1-5] in your code.
MYSQL document mention that clearly
We strongly recommend that you do not use numbers as enumeration values, because it does not save on storage over the appropriate TINYINT or SMALLINT type, and it is easy to mix up the strings and the underlying number values (which might not be the same) if you quote the ENUM values incorrectly. If you do use a number as an enumeration value, always enclose it in quotation marks. If the quotation marks are omitted, the number is regarded as an index. See Handling of Enumeration Literals to see how even a quoted number could be mistakenly used as a numeric index value.
Check this out : MYSQL DOC Enumeration Limitations
:)
You should try with this following ways.
The type for the result can be one of the following values:
BINARY[(N)]
CHAR[(N)]
DATE
DATETIME
DECIMAL[(M[,D])]
SIGNED [INTEGER]
TIME
UNSIGNED [INTEGER]
Thanks.

Unique ID when creating Hive table from CSV files

I have a list of CSV files that I want to export as Hive tables but I'm pretty sure that some records are redundant in the CSVs. Each record / row in the CSV are identified by a key and I want to generate the table using that key as the primary key . How will I generate the Hive table such that there are no repeating rows?
ROW_NUMBER() OVER([partition_by_clause] order_by_clause)
returns an ascending sequence of integers, starting with 1.
select x, row_number() over(order by x, property) as row_number, property from int_t;
+----+------------+----------+
| x | row_number | property |
+----+------------+----------+
| 1 | 1 | odd |
| 1 | 2 | square |
| 2 | 3 | even |
| 2 | 4 | prime |
| 3 | 5 | odd |
| 3 | 6 | prime |
| 4 | 7 | even |
| 4 | 8 | square |
| 5 | 9 | odd |
| 5 | 10 | prime |
| 6 | 11 | even |
| 6 | 12 | perfect |
| 7 | 13 | lucky |
| 7 | 14 | lucky |
| 7 | 15 | lucky |
| 7 | 16 | odd |
| 7 | 17 | prime |
| 8 | 18 | even |
| 9 | 19 | odd |
| 9 | 20 | square |
| 10 | 21 | even |
| 10 | 22 | round |
+----+------------+----------+

how to alter a mysql table to add a column which contains a common value for all rows by checking another columns repeating value

how to alter a mysql table to add a column which contains a common value for all rows by checking another columns repeating value.
+----+----------+--------------+
| id | inode | name |
+----+----------+--------------+
| 1 | 12059010 | IwnsuAaJUFaa |
| 2 | 12059015 | IwnsuAaJUFab |
| 3 | 12059016 | IwnsuAaJUFac |
| 4 | 12059017 | IwnsuAaJUFad |
| 5 | 12059018 | IwnsuAaJUFae |
| 6 | 12059019 | IwnsuAaJUFaf |
| 7 | 12059020 | IwnsuAaJUFag |
| 8 | 12059021 | IwnsuAaJUFah |
| 9 | 12059022 | IwnsuAaJUFai |
| 10 | 12059023 | IwnsuAaJUFaj |
| 11 | 12059013 | iPhZIWtZdSaa |
| 12 | 12059015 | iPhZIWtZdSab |
| 13 | 12059016 | iPhZIWtZdSac |
| 14 | 12059017 | iPhZIWtZdSad |
| 15 | 12059018 | iPhZIWtZdSae |
| 16 | 12059019 | iPhZIWtZdSaf |
| 17 | 12059020 | iPhZIWtZdSag |
| 18 | 12059021 | iPhZIWtZdSah |
| 19 | 12059022 | iPhZIWtZdSai |
| 20 | 12059023 | iPhZIWtZdSaj |
+----+----------+--------------+
i need a fourth column having a common number for all rows group by same "inode" number.
Add the column using something like
ALTER TABLE [tablename] ADD [columname] [columntype]
Change the content of that column using UPDATE.