Wednesday 26 April 2017

SQL Query interview question part - 3

Here I just created Employee table and on the basis of Write Some common query  which generally asking in interview.

CREATE TABLE [dbo].[tblEmployee](
[EmployeeID] [int] IDENTITY(1,1)  NOT NULL,
[LastName] [nvarchar](20) NOT NULL,
[FirstName] [nvarchar](10) NOT NULL,
[Title] [nvarchar](30) NULL,
[BirthDate] [datetime] NULL,
[HireDate] [datetime] NULL,
[Address] [nvarchar](60) NULL,
[City] [nvarchar](15) NULL,
[Country] [nvarchar](15) NULL
)
GO

 SELECT * FROM [tblEmployee]


1. Ques: List of all employee from tblEmployee table whose "FirstName" start with latter 'a'.

Answer: SELECT * FROM [tblEmployee] WHERE FirstName like 'a%'



2. Ques:  List of all employee from tblEmployee table whose "FirstName" start with any single character between 'a-j'.

Answer: SELECT * FROM [tblEmployee] WHERE FirstName like '[a-j]%'



3.Ques: Get only Year part of "HireDate".
Answer:SELECT DATEPART(YEAR, HireDate) FROM [tblEmployee]


No comments:

Post a Comment

Thank you for comment