DATEDIFF Function in SQL Server

DATEDIFF Function in SQL Server

The DATEDIFF Function is used to calculate the difference between two dates. So let's have a look at a practical example of how to use a DATEDIFF Function in SQL Server The DATEDIFF Function The SQL Server DATEDIFF Function is used to calculate the difference between two dates. Syntax
Difference between Clustered and Non-Clustered Index Data Structures

Difference between Clustered and Non-Clustered Index Data Structures

Indexes-Indexing is way to sort and search records in the table. It will improve the speed of locating and retrieval of records from the table.It can be compared with the index which we use in the book to search a particular record. In Sql Server there are two types of Index 1) Clustered Index 2) Non Clustered Index Clustered Index:- Clustered index physically stored the data of the table in the order of the keys values and the data is resorted every time whenever a new value is inserted or a value is updated in the column on which it is defined.
SQL Server CTE Basics

SQL Server CTE Basics

What is Common Table Expression (CTE)? A common table expression (CTE) is a temporary storage result set, which will be accessible within the next execution scope of a query. That means we didn’t get CTE result after the second query statement. A CTE is similar to a derived table in that it is not stored as an object and lasts only for the duration of the query. Unlike a derived table, a CTE can be self-referencing and can be referenced multiple times in the same query.
Difference Between Union vs. Union All in SQL Server

Difference Between Union vs. Union All in SQL Server

UNION The UNION command is used to select related information from two tables, much like the JOIN command. However, when using the UNION command all selected columns need to be of the same data type. With UNION, only distinct values are selected. UNION ALL The UNION ALL command is equal to the UNION command, except that UNION ALL selects all values. The difference between Union and Union all is that Union all will not eliminate duplicate rows, instead it just pulls all rows from all tables fitting your query specifics and combines them into a table.
SQL Server DATEADD Function to Add or Subtract Dates

SQL Server DATEADD Function to Add or Subtract Dates

This function is used to add or subtract specified time interval from dates in SQL Server. Generally DATEADD function will take 3 arguments. Declaration of DATEADD function: DATEADD (datepart, number, date) In this function 1st Argument "datepart" is the interval type we need to add or subtract for example day, month, year, hour, minute, second. Datepart can be one of the following:
ISNULL function in SQL Server

ISNULL function in SQL Server

ISNULL ( check_expression , replacement_value ) Replaces NULL with the specified replacement value. The value of check_expression is returned if it is not NULL; otherwise, replacement_value is returned after it is implicitly converted to the type of check_expression, if the types are different. Example: create table Tab(id int,name char(10)) insert into Tab values(1,'Vikas') insert into Tab values(2,null) insert into Tab values(3,null) insert into Tab values(4,'Arun') select * from Tab select id,isnull(name,'No data') as name from Tab
SQL SERVER – CASE Statement Examples and Explanation

SQL SERVER – CASE Statement Examples and Explanation

CASE expressions can be used in SQL anywhere an expression can be used. Example of where CASE expressions can be used include in the SELECT list, WHERE clauses, HAVING clauses, IN lists, DELETE and UPDATE statements, and inside of built-in functions. Two basic formulations for CASE expression 1) Simple CASE expressions A simple CASE expression checks one expression against multiple values. Within a SELECT statement, a simple CASE expression allows only an equality check; no other comparisons are made. A simple CASE expression operates by comparing the first expression to the expression in each WHEN clause for equivalency. If these expressions are equivalent, the expression in the THEN clause will be returned.