Category Archives: SQL

SQL Server – Generating Date Range With CTE

My job was to create a report for monthly totals of a specific year. It will compute monthly totals from April 1 of that year to March 31 of the next year and must return exactly 12 rows for that … Continue reading

Posted in SQL, SQL Server | Tagged , , , , , | 2 Comments

SQL Server – Using Temporary Tables

The original query was almost perfect – it displays the daily totals for a given month. However, specs changed and they need to add the grand total to the last row. Then another specs for the MAX and MIN rows. … Continue reading

Posted in SQL, SQL Server | Tagged , , , , | Leave a comment

SQL Server – Dynamic Order By Clause

Yes, I’m too busy for SQL scripting job these recent weeks. I have a union select query that needed to be sorted per union but since it is not allowed to have order by in my unions, I have to … Continue reading

Posted in SQL, SQL Server | Tagged , , , , | Leave a comment

SQL Server Import/Export to CSV

There are tools that will help you in importing or exporting CSV files to and from SQL Server databases. However, using them will slow you down for a factor of 20 because of those click, next, next, next wizard thing. … Continue reading

Posted in SQL, SQL Server | Tagged , , , , , , | Leave a comment

SQL Server – Select Nth Row

Seems like I’m now stuck with .NET development and the current tasks where developing SQL scripts. One of the spec was to return the first record, second record and third record as columns for a row. I know how to … Continue reading

Posted in SQL, SQL Server | Tagged , , , , , , , , | Leave a comment

SQL Server – Dynamic Where Clause

Things can be neatly done in application level by concatenating where clause however, there are times when you are out of that application and all you can do is SQL Query. I have found a good resource to do so … Continue reading

Posted in Database, SQL | Tagged , , , , | Leave a comment

Updating Multiple Rows in MySQL

There comes a time when you need to update multiple rows with different values. You can update multiple rows with the same value, but when dealing with different values for different rows, it becomes a difficult task. Yes there are … Continue reading

Posted in Database, MySQL, SQL | Tagged , , , , , , , | Leave a comment

Zend Framework – Zend_Db In Clause

I really thought it was hard to implement the IN clause in Zend Db Select, but after a few research, it was very easy just like the other clause in the WHERE clause. All you need is an array then … Continue reading

Posted in SQL, Zend Framework | Tagged , , , , | 4 Comments

From SQL Script to Zend Db Query

Yesterday, I have debugged an AJAX request that gets a value from the database. It was actually me who developed that module and all calculations and SQL query are based on the specifications given by our analyst. The query was … Continue reading

Posted in SQL, Zend Framework | Tagged , , , , | Leave a comment