Quantcast
Channel: Tweaking4All.com » All Posts
Browsing index pages (34 articles)

SQLite – Avoiding NULL returns (COALESCO)

Sometimes a SELECT returns NULL values, for example when no records were found, for example in something like this: SELECT  (SELECT someid FROM sometable WHERE somevalue=something) ... The sub query...

View Article


SQLite3 – Compare 2 tables, list missing columns/fields

I had to do some comparing of an old table and a new table, and see what columns (fields) are missing. Since it took me quite a while to figure this one out, here my solution. I have 2 tables:...

View Article


Image may be NSFW.
Clik here to view.

SQLite – Convert Unix Time (Epoch or POSIX Time) to DateTime

Working on “Rename My TV Series” I ran into a small issue; the TVDB API (v2) gave back a Unix Epoch formatted DateTime (also known as Unix Time or POSIX time), yet I wanted to store a DateTime in my...

View Article

MySQL – Round CURRENT_TIMESTAMP to nearest minutes

For the Arduino Temperature logged, I was looking for an answer to get temperatures nicely logged by the exact minute.Now we can’t do much on the Arduino side, but we might have been able to do...

View Article

Microsoft SQLServer – How to create a list of my tables

Just a little task I had to look into and figure out:  On Microsoft SQL Server; how do I get a list of all the tabels in my database?A simple SQL statement will reveal this for you: SELECT NAME FROM...

View Article


SQLite – Use COUNT to count rows from multiple tables

In regular SQL, you can count the number of rows in a table with SELECT COUNT(*) FROM Table; Now how would one do this with multiple tables? Below an example by using subqueries, which is pretty...

View Article

SQLite – Update multiple rows, with different values, in one query

I ran into a little “problem” where I wanted to updated multiple rows, in SQLite, each with their own “set” of values.I also wanted to avoid running an update query for each row.So how can this be...

View Article

SQLite – Natural sort of numeric strings quick and easy

So I ran into the issue that I wanted to sort numbers followed by a character in a natural order.Some examples: “480p”, “720p”, “1080p” These would sort (as strings): 1080p, 480p, 720p with a normal...

View Article


MySQL – How to reset Auto Increment fields

In order to reset the auto_increment, in a situation where some of the most recently added rows were deleted, use: ALTER TABLE theTableInQuestion AUTO_INCREMENT=1234 and future insertions will be...

View Article


SQLite – Compact and Optimize your database, using VACUUM, in Lazarus...

A SQLite database can be rebuild (and therefor optimized and defragmented) with the VACUUM SQL statement.Executing this statement requires that you cannot really work with your usual database...

View Article

SQLite – Sort text case insensitive

When you do a ORDER BY a field say “title” which has for example the following values,  title-----  c  a  D  Z  B  X  then with: SELECT ... ORDER BY title ASC; You’ll get: B D X Z a c To sort this...

View Article

SQLite – Ordering text as numbers …

When trying to sort text as number in SQLite, you’ll run into some issues where it does not sort numerical.With a little trick we can order text numerically, even for fields that start with a number....

View Article

MySQL – How to detect if a table exists …

A simple query gives you either ‘0’ if the table does not exist, or >0 if the table(s) exist – you can even use a LIKE statement to look for multiple tables: SELECT count(*)FROM...

View Article


SQLite – Reset Autoincrement Fields

When flushing tables in SQLite, the auto increment fields can be reset as follows for ALL tables: delete from sqlite_sequence; Or as follow for a specific table: delete from sqlite_sequence where...

View Article

VBA/MS Access – Determine age based on date of birth (DOB)

Right after posting the trick fo MySQL on how to determine age, I bumped into this VBA function that does the same: This function calculated age based on [Birthdate] and today (Date) and returns the...

View Article


MySQL – How to calculate an persons' Age based on a Date (DOB)

Sometimes you need to determine the age of a person, given a data of birth (DOB) … there is no given function in MySQL that can do this, but with the following query you’ll be able to determine a...

View Article

MySQL – What is the current value of the auto-increment field of my table?

Sometimes you want to know what the next value of an auto increment field will be of a field in your table. A simple query shows you the last used value (add one to know what the next auto increment...

View Article


MySQL – What is my thread or connection ID?

Sometimes a query can go haywire, often I do recognize which of the connections/processes is mine based on the SQL statement that is running, but sometimes it can be hard for example when my query...

View Article

SQLite – Use COUNT to count rows from multiple tables

In regular SQL, you can count the number of rows in a table with SELECT COUNT(*) FROM Table; Now how would one do this with multiple tables? Below an example by using subqueries, which is pretty...

View Article

SQLite – Update multiple rows, with different values, in one query

I ran into a little “problem” where I wanted to updated multiple rows, in SQLite, each with their own “set” of values.I also wanted to avoid running an update query for each row.So how can this be...

View Article
Browsing index pages (34 articles)


Latest Images