Thursday, 31 March 2011

SQL DateName

DATENAME()

DATENAME() is very common and most useful function to find out the date name from the datetime value.
Example
 
-- Get Today
SELECT DATENAME(dw, getdate()) AS 'Today Is'
-- Get Mont name
SELECT DATENAME(month, getdate()) AS 'Month'

Output :
 Today Is Saturday
   Month IsAugust

Parameter Array in asp.net

Parameter Array
Parameter arrays allow a variable number of arguments to be passed into a function member. The definition of the parameter has to include the params modifier, but the use of the parameter has no such keyword. A parameter array has to come at the end of the list of parameters, and must be a single-dimensional array. When using the function member, any number of parameters (including none) may appear in the invocation, so long as the parameters are each compatible with the type of the parameter array. Alternatively, a single array may be passed, in which case the parameter acts just as a normal value parameter. For example:
void ShowNumbers (params int[] numbers)
{
foreach (int x in numbers)
{
Console.Write (x+" ");
}
Console.WriteLine();
}
...

int[] x = {1, 2, 3};
ShowNumbers (x);
ShowNumbers (4, 5);

Output:
1 2 3
4 5


private string Concatenate(string separator, params object[] parts)
{
System.Text.StringBuilder buffer = new System.Text.StringBuilder();
string sepValue = "";
foreach (object o in parts)
{
buffer.AppendFormat("{0}{1}", sepValue, o);
sepValue = separator;
}
return buffer.ToString();
}
Output parametersLike reference parameters, output parameters don't create a new storage location, but use the storage location of the variable specified on the invocation. Output parameters need the out modifier as part of both the declaration and the invocation - that means it's always clear when you're passing something as an output parameter.
Output parameters are very similar to reference parameters
Example :
void Foo (out int x)
{
// Can't read x here - it's considered unassigned
// Assignment - this must happen before the method can complete normally
x = 10;
// The value of x can now be read:
int a = x;
}


// Declare a variable but don't assign a value to it
int y;

// Pass it in as an output parameter, even though its value is unassigned
Foo (out y);
// It's now assigned a value, so we can write it out:
Console.WriteLine (y);

Output:
10

Update Trigger

Create TRIGGER Tgr_Update  ON  LeaveDetails


AFTER UPDATE
AS
BEGIN
Select  Top 1 @Empid = Empid from LeaveDetails 


  IF( @Empid > 0 AND @Empid IS NOT NULL)
 

   BEGIN
          update dbo.MasterLeave set TotalLeaveWithoutPay = 0, RemainingLeave = 1
          where Empid =@Empid
  END
END

SQl Dateadd

select dateadd(dd, 30, getdate())

SQl First day of the Month

------------------Take First day of the Month ---------------

DECLARE @pInputDate          DATETIME
DECLARE @vOutputDate        DATETIME


set @pInputDate='4/25/2011' April Month


    SET @vOutputDate = CAST(YEAR(@pInputDate) AS VARCHAR(4)) + '/' +   CAST(MONTH(@pInputDate) AS VARCHAR(2)) + '/01'
    SET @vOutputDate = DATEADD(DD,0, DATEADD(MM, 0, @vOutputDate))
o/p= 1 April 2011

Sql ISDate

select isdate(getdate())