SQL Journey

  • Your Email ID:

    Join 6 other followers

  • Top Rated

  • Bookmarks

  • Twitter Updates

  • Blog Stats

    • 16,734 hits
  • SocialVibe


Posts Tagged ‘Reporting’

Generate Report with Alternate Order of an Attribute (say Gender) in SQL Server

Posted by Prashant on June 23, 2010

Some times we may need to generate a report which display employees/customers in alternate order of any particular attribute.This post describes for employees with alternate order of Gender i.e. first a Male employee then a Female employee and so on or vice versa.

In SQL Server this is just a simpler way. There could be may ways to do this. Here is my set based approach with ROW_NUMBER() function.

DECLARE @EMPLOYEE TABLE
(
NAME VARCHAR(100) NOT NULL,
GENDER VARCHAR(1) NOT NULL
)

--Populate sample data
INSERT INTO @EMPLOYEE(NAME,GENDER) VALUES
('Anup','M'), ('Sheetal','F')
,('Sonam','F'), ('Payal','F')
,('Parul','F'), ('Peter','M')
,('Rahul','M'), ('Roxy','F')
,('Preeti','F'), ('Manav','M')

SELECT * FROM @EMPLOYEE

--Result
;WITH CTE(SEQ,ENAME,GENDER)
AS
(
SELECT ROW_NUMBER() OVER(PARTITION BY GENDER ORDER BY GENDER), NAME, GENDER FROM @EMPLOYEE
)
SELECT ENAME,GENDER FROM CTE
ORDER BY SEQ, GENDER DESC
GO
 

Also put your valuable suggestions on this.

Posted in CTE, Functions, Interview Questions, Reporting, ROW_NUMBER(), SQL Server | Tagged: , , , , , , , | Leave a Comment »

SQL Server Reporting Tool – SqlAnswersQuery

Posted by Prashant on June 21, 2010

Here is a FREE tool SqlAnswersQuery you can use for SQL Server reporting purposes.  In fact this tool is also compatible with other databases like Microsoft Access, Oracle, MySQL and DB2

You can download it from http://www.sqlanswers.com/Software/SAQ/Default.aspx.

I found it interesting. Let me know your experience with this tool.

Posted in General, Reporting, SQL Server, SQL Server Tools | Tagged: , , , , , , | 2 Comments »

 
Follow

Get every new post delivered to your Inbox.