We can use Cross Join with WHERE clause and Without WHERE clause, When we use the Cross Join without WHERE clause,produces the Cartesian results from the tables. The resultset contains records that are multiplication of record number from both the tables. Continue reading “Using Cross Joins”
Tag: Sql Server tutorial
System Databases in SQL Server
SQL server installation create some system databases automatically, you can see these database in your SQL server management studio: Continue reading “System Databases in SQL Server”
Using COALESCE in SQL Select Query
COALESCE function returns the first nonnull expression among its arguments. you can use the COALESCE function like as: Continue reading “Using COALESCE in SQL Select Query”
About Sql Server 2005
Microsoft SQL Server is a relational database management system developed by Microsoft. SQL Server 2005 was released in October 2005. It is the successor of the Microsoft SQL Server 2000. Continue reading “About Sql Server 2005”
Using Aliases in SQL Server
You can use some alias for table in the select query for better readability of the query, Aliases of the table are very useful when you are using complex query with multiple lines. Aliases of the tables in the Sql server are also called as a correlation name or range variable. Continue reading “Using Aliases in SQL Server”
Join in SQL Server
Joins are used to extract information from more than one table based on the related column/columns means you can retrieve data from two or more tables based on logical relationships between the tables. Continue reading “Join in SQL Server”
UPDATE Statement in SQL Server
Update statement is different from INSERT and DELETE statements.UPDATE statements is used for updating a single records to multiple records. UPDATE statements use a WHERE clause, same as SELECT statement. Continue reading “UPDATE Statement in SQL Server”
Using IN in SQL Server
IN operator we use when we Determines whether a specified value matches any value in a sub query or a list. The IN operator allows you to specify multiple values in a WHERE clause.it also helps reduce the need to use multiple OR conditions. Continue reading “Using IN in SQL Server”
DATEPART() function in SQL Server
DATEPART() function returns a value equal to the part of a specified date.
Summery
DATEPART(datepart, date)
where date is the valid date or a string in date format
and datepart can be one of the following:
datepart | Abbreviation |
---|---|
year | yy, yyyy |
quarter | qq, q |
month | mm, m |
dayofyear | dy, y |
day | dd, d |
week | wk, ww |
weekday | dw, w |
hour | hh |
minute | mi, n |
second | ss, s |
millisecond | ms |
Example
Suppose you have a table ‘tbl_employee’
tbl_employee
Employee Id | EmpName | Age | DateOfJoin |
1 | Ankur | 28 | 11/04/1995 |
2 | David | 32 | 11/04/2002 |
The following query return the date of joining of the Ankur:
SELECT datepart("year", DateOfJoin)
Output will be:
—————–
1995
Now if you want to current year, you can use the following query:
SELECT DATEPART("Year",GETDATE())
–or—
SELECT DATEPART("yy",GETDATE())
GETDATE() function return the current date.
DATEDIFF() function in SQL Server
DATEDIFF() function is very useful when we are working with date operations. DATEDIFF function return the difference between date items in days, weeks, minutes, years and hours. It can also used with WHERE clause. Continue reading “DATEDIFF() function in SQL Server”