Search This Blog

Tuesday, June 12, 2012

ISNUMERIC SQL Server

SQL Server > Built-In Functions > ISNUMERIC

ISNUMERIC returns 1 when the input expression evaluates to a valid numeric data type; otherwise it returns 0

Example:

IF OBJECT_ID(N'tbl1', N'U') IS NOT NULL
       DROP TABLE tbl1;
GO

CREATE TABLE tbl1
(
       id     int ,
       code   varchar(50)
);
GO

INSERT INTO tbl1 values  (1,'aaa'), (2,'b12') , (3,'345')

SELECT
       *
FROM
       tbl1
WHERE
       ISNUMERIC(code) = 1

Result:
 
id code
3  345

 

 






C# Nullable DateTime

C# > System Namespace > DateTime > Nullable DateTime

// Error Cannot convert null to 'System.DateTime' because it is a non-nullable value type 
   
DateTime AgendaValidFrom;
AgendaValidFrom = null;

Solution:
Add ? to DateTime

DateTime? AgendaValidFrom = null; // Declare a nullable DateTime instance and assign to null.





Monday, June 11, 2012

Delete from table using join SQL Server

SQL Server > DML > DELETE

Removes rows from a table.

Example

To delete from tables using join you must specify an alias for the table from which to delete data.

IF OBJECT_ID(N'tbl1', N'U') IS NOT NULL
       DROP TABLE tbl1;
GO
IF OBJECT_ID(N'tbl2', N'U') IS NOT NULL
       DROP TABLE tbl2;
GO

CREATE TABLE tbl1
(
       id           int ,
       name   varchar(50)
);
GO
CREATE TABLE tbl2
(
       id           int ,
       name   varchar(50)
);
GO

INSERT INTO tbl1 values  (1,'john'), (2,'dan') , (3,'laura')
INSERT INTO tbl2 values  (1,'john')
GO

select * from tbl1
--id name
--1 john
--2 dan
--3 laura
DELETE
  a
from
  tbl1 a
join tbl2 b on a.id = b.id

select * from tbl1

--id name
--2 dan
--3 laura



GO






COUNT_BIG SQL Server

SQL Server Built-in Functions COUNT_BIG


COUNT_BIG is the same like COUNT but returns bigint data type value.







Saturday, June 9, 2012

Date Functions C#

C# > System Namespace > DateTime > Add Methods

Returns a new DateTime that adds the specified number of  years, days, minutes, months, seconds to the value of this instance.

Example:

DateTime AgendaValidTill = DateTime.Now.AddYears(10);
// add days
AgendaValidTill = DateTime.Now.AddDays(10);
AgendaValidTill = DateTime.Now.AddMinutes(10);
AgendaValidTill = DateTime.Now.AddMonths(10);
AgendaValidTill = DateTime.Now.AddSeconds(10);








Wednesday, June 6, 2012

Date functions SQL Server

SQL Server > Date&Time > Date Functions



-- Selecting the Current Year/Get Current Year/Separate Year Part from Date
Select DatePart(YY, GetDate()) as Current_Year
-- Selecting the Current Quarter/Get Current Quarter/Separate Quarter Part from Date
Select DatePart(QQ, GetDate()) as Current_Quarter
-- Selecting the Current Month/Get Current Month/Separate Month Part from Date
Select DatePart(MM, GetDate()) as Current_Month
-- Selecting the Current Hour/Get Current Hour/Separate Hour Part from Date
Select DatePart(HH, GetDate()) as Current_Hour
-- Selecting the Current Minute/Get Current Minute/Separate Minute Part from Date
Select DatePart(minute, GetDate()) as Current_Minute

-- Selecting the Name of Current Month/Get Name of Current Month/Separate Month Part from Date and display its Name
Select DateName(month, GetDate()) as Current_Month_Name
-- Selecting the Name of Current Month/Get Name of Current Month/Separate Month Part from Date and display its Name
Select DateName(day, GetDate()) as Current_Day
-- Selecting the Name of Current Month/Get Name of Current Month/Separate Month Part from Date and display its Name
Select DateName(wk, GetDate()) as Current_Week





Restart asp.net application

ASP.NET > HttpRuntime > UnloadAppDomain


HttpRuntime.UnloadAppDomain Method

Terminates the current application. The application restarts the next time a request is received for it.

UnloadAppDomain is useful for servers that have a large number of applications that infrequently receive requests. Rather than keep application resources alive for the lifetime of the process, UnloadAppDomain allows programmatic shutdown of unused applications.

Example

Restart asp.net application


using System;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace editor.Admin
{
    public partial class restart : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            System.Web.HttpRuntime.UnloadAppDomain();
        }
    }
}