sql
How to calculate age (in years) based on Date of Birth and getDate()
There are issues with leap year/days and the following method, see the update below: try this: OUTPUT: UPDATE here are some more accurate methods: BEST METHOD FOR YEARS IN INT you can change the above 10000 to 10000.0 and get decimals, but it will not be as accurate as the method below. BEST METHOD FOR … Read more
How to do a batch insert in MySQL
From the MySQL manual INSERT statements that use VALUES syntax can insert multiple rows. To do this, include multiple lists of column values, each enclosed within parentheses and separated by commas. Example:
Equivalent of explode() to work with strings in MySQL
MYSQL has no explode() like function built in. But you can easily add similar function to your DB and then use it from php queries. That function will look like: Usage: The example above will return apple. I think that it will be impossible to return array in MySQL so you must specify which occurrence … Read more
DATEDIFF function in Oracle
In Oracle, you can simply subtract two dates and get the difference in days. Also note that unlike SQL Server or MySQL, in Oracle you cannot perform a select statement without a from clause. One way around this is to use the builtin dummy table, dual:
Fatal error: Call to a member function query() on null
First, you declared $db outside the function. If you want to use it inside the function, you should put this at the begining of your function code: And I guess, when you wrote: what you really wanted was:
Oracle: If Table Exists
The best and most efficient way is to catch the “table not found” exception: this avoids the overhead of checking if the table exists twice; and doesn’t suffer from the problem that if the DROP fails for some other reason (that might be important) the exception is still raised to the caller: ADDENDUM For reference, … Read more
Cannot create an instance of OLE DB provider Microsoft.Jet.OLEDB.4.0 for linked server null
I have MS Sql server 2012, and Office 2013. This seems to be very finicky, so you may have to adjust to your particular versions. Download the Microsoft.ACE.OLEDB.12.0 for Windows, 64 bit version found here: https://www.microsoft.com/en-us/download/details.aspx?id=13255 Install it on your server. Check the user running SQL Server and make sure that user has access to the … Read more
Convert SQL to LINQ Query
Have you tried Linqer http://www.sqltolinq.com An SQL-> LINQ converter.. Or LINQPad http://www.linqpad.net/
Get everything after and before certain character in SQL Server
If you want to get this out of your table using SQL, take a look at the following functions that will help you: SUBSTRING and CHARINDEX. You can use those to trim your entries. A possible query will look like this (where col is the name of the column that contains your image directories: Bit of an ugly beast. It … Read more