Total Pageviews

Thursday, 19 April 2012

SQL Query to find 3rd Oldest Employee



--Solution 1
select * from
(select top 3 ROW_NUMBER() OVER(order by DateOfBirth) AS row,* from Employee)Emp
where ROW=3

--Solution 2 
select top 1 * from
(select top 3 * from Employee order by DateOfBirth) Emp order by DateOfBirth desc


if any more solution please comment

Friday, 13 April 2012

ASP.NET Page Events


private void AllEvents()
    {
        Page.AbortTransaction += new EventHandler(Page_AbortTransaction);
        Page.CommitTransaction += new EventHandler(Page_CommitTransaction);
        Page.DataBinding += new EventHandler(Page_DataBinding);
        Page.Disposed += new EventHandler(Page_Disposed);
        Page.Error += new EventHandler(Page_Error);
        Page.Init += new EventHandler(Page_Init);
        Page.InitComplete += new EventHandler(Page_InitComplete);
        Page.Load+=new EventHandler(Page_Load);
        Page.LoadComplete += new EventHandler(Page_LoadComplete);
        Page.PreInit += new EventHandler(Page_PreInit);
        Page.PreLoad += new EventHandler(Page_PreLoad);
        Page.PreRender += new EventHandler(Page_PreRender);
        Page.PreRenderComplete += new EventHandler(Page_PreRenderComplete);
        Page.SaveStateComplete += new EventHandler(Page_SaveStateComplete);
        Page.Unload += new EventHandler(Page_Unload);
       
    }

    void Page_Unload(object sender, EventArgs e)
    {
        throw new NotImplementedException();
    }

    void Page_SaveStateComplete(object sender, EventArgs e)
    {
        throw new NotImplementedException();
    }

    void Page_PreRenderComplete(object sender, EventArgs e)
    {
        throw new NotImplementedException();
    }

    void Page_PreRender(object sender, EventArgs e)
    {
        throw new NotImplementedException();
    }

    void Page_PreLoad(object sender, EventArgs e)
    {
        throw new NotImplementedException();
    }

    void Page_PreInit(object sender, EventArgs e)
    {
        throw new NotImplementedException();
    }

    void Page_LoadComplete(object sender, EventArgs e)
    {
        throw new NotImplementedException();
    }

    void Page_InitComplete(object sender, EventArgs e)
    {
        throw new NotImplementedException();
    }

    void Page_Init(object sender, EventArgs e)
    {
        throw new NotImplementedException();
    }

    void Page_Error(object sender, EventArgs e)
    {
        throw new NotImplementedException();
    }

    void Page_Disposed(object sender, EventArgs e)
    {
        throw new NotImplementedException();
    }

    void Page_DataBinding(object sender, EventArgs e)
    {
        throw new NotImplementedException();
    }

    void Page_CommitTransaction(object sender, EventArgs e)
    {
        throw new NotImplementedException();
    }

    void Page_AbortTransaction(object sender, EventArgs e)
    {
        throw new NotImplementedException();
    }


Tuesday, 3 April 2012

SQL QUERY Help


--Coinage

Declare @sal INT;
SET @sal =5988;
select @sal,@sal/1000 AS T1000,
         @sal%1000/500 AS T500,
         @sal%1000%500/100 AS T100,
         @sal%1000%500%100/50 AS T50,
         @sal%1000%500%100%50/20 AS T20,
         @sal%1000%500%100%50%20/10 AS T10,
         @sal%1000%500%100%50%20%10/5 AS T5,
         @sal%1000%500%100%50%20%10%5/2 AS T2,
         @sal%1000%500%100%50%20%10%5%2 AS T1

--Table Valued Function

CRAETE FUNCTION Coinage
(
@sal BIGINT
)
RETURNS TABLE
AS
RETURN
(SELECT @sal AS T,
             @sal/1000 AS T1000,
         @sal%1000/500 AS T500,
         @sal%1000%500/100 AS T100,
         @sal%1000%500%100/50 AS T50,
         @sal%1000%500%100%50/20 AS T20,
         @sal%1000%500%100%50%20/10 AS T10,
         @sal%1000%500%100%50%20%10/5 AS T5,
         @sal%1000%500%100%50%20%10%5/2 AS T2,
         @sal%1000%500%100%50%20%10%5%2 AS T1
         )
        

--SELECT * FROM Coinage(59216588345)

--OUTPUT Keyword
declare @i INT;

exec sp_executeSQL N' SELECT @i=5',N'@i INT OUTPUT',@i OUTPUT;

select @i+9

---------------------------------------------------------------


CREATE function [dbo].[Date](@Year int, @Month int, @Day int)
-- returns a datetime value for the specified year, month and day
returns datetime
as
    begin
  
    return dateadd(month,((@Year-1900)*12)+@Month-1,@Day-1)
    end
 ---------------------------------------------------------------

CREATE function [dbo].[DateOnly](@DateTime DateTime)
-- Returns @DateTime at midnight; i.e., it removes the time portion of a DateTime value.
returns datetime
as
    begin
    return dateadd(dd,0, datediff(dd,0,@DateTime))
    end

 ---------------------------------------------------------------

CREATE function [dbo].[DateTime](@Year int, @Month int, @Day int, @Hour int, @Minute int, @Second int)
-- returns a dateTime value for the date and time specified.
returns datetime
as
    begin
    return dbo.Date(@Year,@Month,@Day) + dbo.Time(@Hour, @Minute,@Second)
    end



------------- XML DataType 


DECLARE @XMLTable TABLE(GameHistory XML)
INSERT INTO @XMLTable VALUES( '<game xmlns="http://my.name.space">
      <move>
       <player>white</player>
       <piece>pawn</piece>
       <start>A2</start>
       <end>A3</end>
      </move>
      <move>
       <player>black</player>
       <piece>pawn</piece>
       <start>D7</start>
       <end>D6</end>     
      </move>
     </game>');

WITH XMLNAMESPACES(DEFAULT 'http://my.name.space')
SELECT GameHistory.query('/game/move[1]') FROM @XMLTable


.....TO GET Defination/text/code of SP FUNCTION VIEW 


sp_helptext 'View_SMS'
sp_helptext 'SP_SMS'
sp_helptext 'FN_SMS'



------SQL QUERY for DateOnly and TimeOnly from DateTime


SELECT  GETDATE() AS theDateTime,
            DATEADD(dd, DATEDIFF(dd, 0, GETDATE()), 0) AS theDate,
            DATEADD(dd, -DATEDIFF(dd, 0, GETDATE()), GETDATE()) AS theTime

Here 0 can be replaced with any number. 0 means CAST(0 AS DATETIMEthat is 1900-01-01 00:00:00

Monday, 2 April 2012

Games