My database layout needs to create new schema for each new customer. Currently I use internal function I found on the net and modified a little bit. CREATE FUNCTION copy_schema( source_schema …
SQL Server query to show summary list for particular months or between dates
I have an attendance table which contains student’s attendance date and attendance status. Is there any way to display a summary something like this: Student 20-09-2012 21-09-2012 22-09-2012 23-09-…
How to do NULLS LAST in SQLite?
I’d like to sort my result with all NULL columns last (NULLS LAST), as specified in the SQL:2003 extension T611. Sadly, SQLite seems to not support it. Is there a clever workaround?
Inserting NULL into MySQL timestamp
I’m observing unexpected behavior with inserting/updating NULL in a MySQL timestamp column. Consider the following statements. The first insert (when hiredate is not specified in the SQL, hireDate is null(0) which is expected. However when an explicit null passed in SQL, the current date time is inserte…
Return value at max date for a particular id
Here’s my sql server table This seems like it should be easy to do, but I don’t know why I’m stuck. I’d like to select ONLY the max(date) and value at that max(date) for each id. I want to ignore all other dates that aren’t the max(date) with respect to each id. Here’s what…
Trigger and update to a row in SQL Server after it’s been updated
Is this the best way to keep a simple track of changes to a database row: So any update to a row in [121s] will result in the modified column being updated. It works, but I’m not sure if it’s the best way to achieve this. I’m a litle confused over this line: …and how it knows it’…
cannot get simple PostgreSQL insert to work
I’m trying to do a simple insert into a postgres table, but am getting an error that the value I’m trying to insert is being interpreted as a column name Where id is set up to be the primary key, and auto increment, and not null. Those are the boxes I ticked when I set up the table in phpPgAdmin.
Casting NULL type when updating multiple rows
I have a problem when I try to update many rows at the same time. Here is the table and query I use (simplified for better reading): table CREATE TABLE foo ( pkid integer, x integer, y …
Is there a good way to extend the Code-First Migrations
I am starting a new project that uses Entity Framework. I have researched my options for how to create the database and found Code-First Migrations make the most sense (see bottom if you need to know …
Rails ActiveRecord – how to fetch records between two dates
I have two date columns – from_date and to_date in a database table. Example: from_date: 2012-09-10 to_date: 2012-09-30 today: 2012-09-13 I need to fetch all records, if today’s date is between from_date and to_date. How do I do that with a SQL query? If I have loaded the respective record, I can …