Wednesday, April 20, 2011

Oracle's equivalent of SQL Server's TOP command

Rownum is used in Oracle to retrieve the N-top records.

SELECT * FROM emp  WHERE rownum < 2

Note: Some things to keep in mind are that the “>=” or the “>” operators wont work with ROWNUM. Also remember ROWNUM is to only pick the required row from a result set and should not be confused with the position of the record in the table.

you want the first row of an ordered result set, you need to do the following:

SELECT e.*
  FROM (SELECT * FROM emp ORDER BY empno) e
WHERE rownum < 2 ;

The reason why is because rownum is assigned to the result set as the records are retrieved but before they are sorted. For that reason you must order the result set in an in-line view before using rownum to retrieve the first row (or any number of first rows for that matter).

Do some R & D in Row_Number() in ORACLE

Friday, April 8, 2011

Using the Open XML SDK 2.0 Classes to create Excel files

The 2007 Microsoft Office system introduces a new file format that is based on XML called Open XML Formats. Microsoft Office Word 2007, Microsoft Office Excel® 2007, and Microsoft Office PowerPoint® 2007 all use these formats as the default file format.
Open XML formats are useful for developers because they are an open standard and are based on well-known technologies: ZIP and XML. Microsoft provides a library for accessing these files as part of the WinFX technologies in the System.IO.Packaging namespace.


The Open XML Format SDK is built on top of the System.IO.Packaging API and provides strongly typed part classes to manipulate Open XML documents.


The Open Xml SDK 2.0 add-on can be downloaded from the below Microsoft Site for free of cost.










This download requires the following:
        The Microsoft .NET Framework version 3.5 SP1.


There will be two msi files.


1.       Installing OpenXMLSDKv2.0.msi file will register DocumentFormat.OpenXML dll  in your local GAC.
2.       Installing OpenXMLSDKTool.msi will give access to the tool which will create code files
for the given office files.


There is a very good sample too in the following MSDN site.





And also Microsoft provides code samples as msi file for Visual Studio 2010 users.










Note: If the .NET Framework 3.5 SP1 is not already installed on the computer, the setup wizard asks you to install
the .NET Framework 3.5 SP1 first. The default installation path of the SDK is

%systemdrive%\Program Files\Open XML Format SDK\V2.0


Other related useful links for Open XML SDK 2.0