Monday, May 21, 2012

Javascript Math Round



The required number argument is the value to be rounded to the nearest integer.
For positive numbers, if the decimal portion of number is 0.5 or greater, the return value is equal to the smallest integer greater than number. If the decimal portion is less than 0.5, the return value is the largest integer less than or equal to number.
For negative numbers, if the decimal portion is exactly -0.5, the return value is the smallest integer that is greater than the number.
For example, Math.round(8.5) returns 9, but Math.round(-8.5) returns -8.


MSDN Ref LINK


For Example :

var a=Math.round(2.60);      [3]
var b=Math.round(2.50);      [3]
var c=Math.round(2.49);      [2]
var d=Math.round(-2.60);    [-3]
var e=Math.round(-2.5);      [-2]
var f=Math.round(-2.49);     [-2]








Thursday, May 17, 2012

Script All the Stored Procedures in The Database


Script All the Stored Procedures in The Database

In Sql Server 2005 and 2008 you can script the stored procedure in Management Studio by right clicking on Store Procedure name and clicking on “Script Store Procedure as” and then “Create To”.
But if you want to script all the Stored Procedures in the database programmatically, then here is the simple T-SQL query for it -
To script All the Stored Procedures in the Database :
SELECT    O.Name as ProcName
        ,M.Definition as CreateScript
        ,O.Create_Date
        ,O.Modify_Date
FROM sys.sql_modules as M INNER JOIN sys.objects as O
ON M.object_id = O.object_id
WHERE O.type = 'P'
If the Stored Procedure is created with ENCRYPTION option then you will get the NULL in the definition column.
Similarly,
To script All the Views in the Database :
SELECT    O.Name as ProcName
        ,M.Definition as CreateScript
        ,O.Create_Date
        ,O.Modify_Date
FROM sys.sql_modules as M INNER JOIN sys.objects as O
ON M.object_id = O.object_id
WHERE O.type = 'V'
To script All the Functions in the Database :
SELECT    O.Name as ProcName
        ,M.Definition as CreateScript
        ,O.Create_Date
        ,O.Modify_Date
FROM sys.sql_modules as M INNER JOIN sys.objects as O
ON M.object_id = O.object_id
WHERE O.type = 'FN'
For scripting all Triggers small modification is required, instead of sys.objects I joined thesys.triggers with sys.sql_modules.
To script All the Triggers in the Database :
SELECT    O.Name as ProcName
        ,M.Definition as CreateScript
        ,O.Create_Date
        ,O.Modify_Date
FROM sys.sql_modules as M INNER JOIN sys.triggers as O
ON M.object_id = O.object_id
Resource Reference Link