DENSE_RANK() function in MS SQL Server

Category: IT, MS SQL Server, SQL Tags: , , , Comments: 0 »

As we can read in Books Online in SQL Server
Ranking functions return a ranking value for each row in a partition. Depending on the function that is used, some rows might receive the same value as other rows. Ranking functions are nondeterministic.
I have created simple example for usage of the Ranking function DENSE_RANK(). We have [...]

Simple SSIS Project – export to flat file, FTP upload, archive (create the package)

Category: IT, MS SQL Server Tags: Comments: 0 »

Microsoft® SQL Server™ Integration Services is the tool that connects the database to the world and works instead of us. I’ll show you how to extract simple data from the database, store the files in a the file system, rename them, upload them on FTP and report the errors to administrator if any. In this first [...]

The difference between WHERE and HAVING filters in SQL Server

Category: IT, MS SQL Server, SQL Tags: , Comments: 0 »

The difference between WHERE and HAVING filters in Transact-SQL queries is that WHERE clause is a filter of all the data, while HAVING filters the GROUP BY data. I’ve prepared a simple example.

USE zlika
GO

– Create table
CREATE TABLE test (
Date DATETIME
, QTY INT
)
GO

– Populate table
INSERT INTO test (Date, QTY)
SELECT ’2009-05-10′, 1
UNION ALL SELECT ’2009-05-10′, 2
UNION ALL [...]

MS SQL Server Cursor Example

Category: IT, MS SQL Server Tags: , Comments: 0 »

The cursors in MS SQL Server are not the best way to manipulate the data, because they need more recourse. If you can escape the usage of cursors, do it. OK, the cursors give us a flexible way of manipulating the information. You can imagine a bundle of information, that we use for move through [...]

Generate filename (Name_Date_Time.txt) for a report with Transact-SQL in Microsoft SQL Server

Category: IT, MS SQL Server Tags: , Comments: 0 »

My ex-colleague asked me how to insert query result in a variable for generate report in Microsoft SQL Server. After few explanations I noticed that she has decided to use SSIS (SQL Server Integration Services) to automate. She sent me an example in which she uses YEAR(), MONTH() and DAY() functions.
– YEAR(), MONTH(), DAY()
SELECT
‘Test_’
+ CAST(YEAR(GETDATE()) AS CHAR(4))
+ ‘-’
+ [...]

Join Tables in MS SQL – FROM or WHERE clause?

Category: IT, MS SQL Server, MySQL Tags: , , Comments: 0 »

I was interested of the different SQL “accents”. According to Microsoft SQL Server learning books, we query like this:

SELECT
*

FROM
table1 INNER JOIN table2
ON table1.PK = table2.FK
GO

The MySQL guys makes queries like this:

SELECT *
FROM table1, table2
WHERE table1.PK = table2.FK;

Using Microsoft SQL Server 2008, I wrote a script to create and populate two tables [...]