| Define MVC Action Filters |
| Action Filters are used in cases where we need to perform some logic either before an action method is called or after an action method runs. |
Define MVC Action Filters
Labels:
MVC
Qualifiers in LINQ
They are LINQ Extension Methods return Boolean Value.
- All
- Any
- Contains
- SquenceEqual
Labels:
LINQ
Main Components in LINQ
There are three Main Components in LINQ
- Standard Query Operator
- Language Extension
- LINQ Provider
Labels:
LINQ
add Minutes to DateTime in Sql Server
We can use DATEADD() function like below to add minutes to DateTime in Sql Server. DATEADD() functions first parameter value can be minute or mi or n all will return the same result. Below example shows how we can add two minutes to Current DateTime in Sql Server:
SELECT GETDATE() 'Now',
DATEADD(minute,2,GETDATE()) 'Now + 2 Minutes'
SELECT GETDATE() 'Now',
DATEADD(mi,2,GETDATE()) 'Now + 2 Minutes'
SELECT GETDATE() 'Now',
DATEADD(n,2,GETDATE()) 'Now + 2 Minutes'
DATEADD(minute,2,GETDATE()) 'Now + 2 Minutes'
SELECT GETDATE() 'Now',
DATEADD(mi,2,GETDATE()) 'Now + 2 Minutes'
SELECT GETDATE() 'Now',
DATEADD(n,2,GETDATE()) 'Now + 2 Minutes'
Labels:
SQL Server
add Hours to DateTime in Sql Server
We can use DATEADD() function like below to add hours to DateTime in Sql Server.
DATEADD() functions first parameter value can be hour or hh all will return the same result. Below example shows how we can add two hours to Current DateTime in Sql Server:
DATEADD() functions first parameter value can be hour or hh all will return the same result. Below example shows how we can add two hours to Current DateTime in Sql Server:
SELECT GETDATE() 'Now',
DATEADD(hour,2,GETDATE()) 'Now + 2 Hours'
SELECT GETDATE() 'Now',
DATEADD(hh,2,GETDATE()) 'Now + 2 Hours'
DATEADD(hour,2,GETDATE()) 'Now + 2 Hours'
SELECT GETDATE() 'Now',
DATEADD(hh,2,GETDATE()) 'Now + 2 Hours'
Labels:
SQL Server
add Seconds to DateTime in Sql Server
We can use DATEADD() function like below to add seconds to DateTime in Sql Server. DATEADD() functions first parameter value can be second or ss or s all will return the same result. Below example shows how we can add two seconds to Current DateTime in Sql Server:
SELECT GETDATE() 'Now',
DATEADD(second,2,GETDATE()) 'Now + 2 Seconds'
SELECT GETDATE() 'Now',
DATEADD(ss,2,GETDATE()) 'Now + 2 Seconds'
SELECT GETDATE() 'Now',
DATEADD(s,2,GETDATE()) 'Now + 2 Seconds'
DATEADD(second,2,GETDATE()) 'Now + 2 Seconds'
SELECT GETDATE() 'Now',
DATEADD(ss,2,GETDATE()) 'Now + 2 Seconds'
SELECT GETDATE() 'Now',
DATEADD(s,2,GETDATE()) 'Now + 2 Seconds'
Labels:
SQL Server
IIF funciton in SQL Server 2012 and give an Example
If you are using SQL Server 2012 you can use IIF and get the same effect as CASE statement.
Create a Table
Create a Table
CREATE TABLE SimpleTable (ID INT, NAME VARCHAR(10))
GO
Insert some value into table
INSERT INTO SimpleTable (ID, NAME)
SELECT 1, 'LAKSHMI'
UNION ALL
SELECT 2, 'NARAYANAN'
UNION ALL
SELECT 3, 'NARAYANAN'
GO
GO
Insert some value into table
INSERT INTO SimpleTable (ID, NAME)
SELECT 1, 'LAKSHMI'
UNION ALL
SELECT 2, 'NARAYANAN'
UNION ALL
SELECT 3, 'NARAYANAN'
GO
UPDATE SimpleTable
SET Gender = IIF(NAME = 'NARAYANAN', 'LAKSHMI', 'NARAYANAN')
GO
SELECT *
FROM SimpleTable
GO
SET Gender = IIF(NAME = 'NARAYANAN', 'LAKSHMI', 'NARAYANAN')
GO
SELECT *
FROM SimpleTable
GO
Labels:
SQL Server
Example for CASE Function in SQL
Create a Table
CREATE TABLE SimpleTable (ID INT, NAME VARCHAR(MAX))
GO
Insert some value into table
INSERT INTO SimpleTable (ID, NAME)
SELECT 1, 'LAKSHMI'
UNION ALL
SELECT 2, 'NARAYANAN'
UNION ALL
SELECT 3, 'NARAYANAN'
GO
CASE FuncitonGO
Insert some value into table
INSERT INTO SimpleTable (ID, NAME)
SELECT 1, 'LAKSHMI'
UNION ALL
SELECT 2, 'NARAYANAN'
UNION ALL
SELECT 3, 'NARAYANAN'
GO
UPDATE SimpleTable
SET Gender = CASE NAME WHEN 'NARAYANAN' THEN 'LAKSHMI' ELSE 'NARAYANAN' END
GO
SELECT *
FROM SimpleTable
GO
SET Gender = CASE NAME WHEN 'NARAYANAN' THEN 'LAKSHMI' ELSE 'NARAYANAN' END
GO
SELECT *
FROM SimpleTable
GO
Labels:
SQL Server