Monday, February 7, 2011

How to find 2nd Highest salary from emp table

CREATE TABLE EMP1 (ID INT IDENTITY (1,1)  ,SAL INT)
INSERT INTO EMP1 VALUES (2000)
INSERT INTO EMP1 VALUES (3000)
INSERT INTO EMP1 VALUES (4000)
INSERT INTO EMP1 VALUES (9000)
INSERT INTO EMP1 VALUES (1000)

----1.2nd Highest salary from emp table .
SELECT * FROM EMP1
select  *  from emp1  e1
where 1=(select count(distinct e2.sal)  from emp1 e2 where e2.sal > e1.sal)
----2.Identifying the duplicate Records in a table .
select * from emp1
SELECT sal,
 COUNT(sal) AS dupsal
FROM emp1
GROUP BY sal
HAVING ( COUNT(sal) > 1 )

How to calculate Running totals and row totals?


cREATE TABLE #TmpTable
(
    ID int, Col1 int, Col2 int,
    RowTotal int, RunningTotal int
)

INSERT INTO #TmpTable SELECT 1, 5, 2, 0, 0
INSERT INTO #TmpTable SELECT 2, 14, 65, 0, 0
INSERT INTO #TmpTable SELECT 3, 34, 22, 0, 0
INSERT INTO #TmpTable SELECT 4, 56, 22, 0, 0
INSERT INTO #TmpTable SELECT 5, 7, 23, 0, 0
go

DECLARE @rowtot int
DECLARE @runtot int
SET @rowtot = 0 -- set rowtotal to 0
SET @runtot = 0 -- set runningtotal to 0
UPDATE #TmpTable
SET RowTotal = @rowtot,
RunningTotal = @runtot,
@rowtot = COALESCE(Col1, 0) + COALESCE(Col2, 0),
@runtot = @runtot + @rowtot
--------------------------------------------------------------
Select * from #tmpTable

Monday, August 24, 2009

Condtional formatting for Dates and Currency....

This is the technique format property of dates
=switch(fields!mylocale.value="DE" ,"d.MM.yy" ,fields!mylocale.value ="UK","d/MM/YY",
feilds!mylocale.value="US","M/d/YY")

This is the technique format property of currency

=switch(fields!mylocale.value="DE" ,"de-DE" ,fields!mylocale.value ="UK","en-GB",
feilds!mylocale.value="US","en-US")

How to display the alternate rows in different color ?

In ssrs you can select detail section of the report
goto the properties,on color goto the expressions--->
write a code
=IIF(ROWNUMBER(NOTHING) MOD 2,"RED","GREEN")

Search This Blog

DAX - Grouping on multiple columns and the count

Please go thorugh the below URL for entire soultion. http://community.powerbi.com/t5/Desktop/DAX-Grouping-on-multiple-columns-and-the-cou...