More often, you may find many interviewers ask you tricky SQL interview queries. Be prepared for this kind of MS SQL queries.
Below are few list that I prepared what I experienced in my day-to-day life.
SELECT 1/2 AS [1/2]
SELECT 1.0/2 AS [1.0/2]
SELECT '' AS 'UnionQuey' UNION ALL SELECT 1
Declare @String_1 Varchar(5) = Null,
@String_2 Varchar(10) = '0123456789'
SELECT COALESCE(@String_1,@String_2) AS [Coalesce]
, ISNULL(@String_1,@String_2) AS [IsNull]
SELECT DISTINCT COUNT(1) AS 'DistinctCount' FROM sys.tables
SELECT COUNT(DISTINCT 1) AS 'CountDistinct' FROM sys.tables
Run above SQL script and see answers. Few of them surely will blow your mind. You may probably think there is bug in MS SQL.!!
Below is answer of all SQL queries.
Be prepared for this kind of queries for that interviewer may ask.!
I will update this post to add more this kind of interesting queries. You can comment below if you know this kind of SQL server tricky queries.
SELECT 'A' UNION ALL SELECT 1
Result: Conversion failed when converting
the varchar value 'A' to data type int.
Google Online Shopping Festival is the most resourceful shopping mela of the year where you can find all the products at prices like never before. It is the best time of the year to buy all heavy products such as mobiles, electronics, apparels and accessories, watches, perfumes, kid’s wear etc. as these products are available […] Continue Reading →
Data migration is often headache process. Some old systems stores “FullName” in a single column.But the most efficient technique is to store full name into FirstName, MiddleName and LastName columns. And for this we need to split Name into First name, Middle Name and Last Name in SQL Server. We can use different functions like CHARINDEX, […] Continue Reading →
Hidesign was founded in the year 1978 by two people and now over the years of struggle the brand has become a fashion icon for urban professionals. It has become an international brand by having a presence in 20 countries across globe and has a presence all over India. The brand is all about professional […] Continue Reading →
Cursor in SQL Server is a control structure which process data row by row. It enables rows in a result to process sequentially. SQL Cursor is a type of iterator which can be used to process any record of table & can modify records according to our needs. To use cursors in SQL procedures, you […] Continue Reading →
In earlier post, I published article about Find duplicate rows in SQL. Now It’s easy when you have small amount of duplicate data. But in million records,it’s very difficult to delete duplicate rows in SQL. Continue with older post, I have added one more duplicate Email.My table will look like below.! Now what I want is, […] Continue Reading →
Order By clause is used to order a number or string of any column of SQL. We can esaily order any column if it;s data-type is INTEGER.Suppose we have column contain data like 2A,1,4,3B,11,111 in VARCHAR column and need to order this column.So below SQL tutorial is about Order by String and number in SQL […] Continue Reading →
Many times we want to block IP Address so particular machine is not able to access website/blog again. People may be hackers,enemies,Invalid clickers or may be another.Below is guide to block IP address from website. Login to Cpanel Account Almost all Hosting providers offers you cPanel.Login to your cPanel,for my example I use BlueHost here. Go to […] Continue Reading →
As a good programmer,you need to use many Date functions in SQL Server.I share here most used Date functions of SQL Server which will do different functionality according to its needs. GETDATE() You can easily retrieve current Date Time in SQL Server using GETDATE() function. Query : select GETDATE() CONVERT() Many times,We want to convert Date Format […] Continue Reading →
A stored procedure is a group of Transact-SQL statements compiled into a single execution plan.(Source: MSDN).To create stored procedure in SQL Server,Go to Database ->Programmability->Stored Procedures.Click right click and click on New Stored Procedure.It will create a new Query Window for you. You will get above image script in your SQL Server.In this script,you have to […] Continue Reading →