Category Archives: SQL Server

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