Top 6 SQL Tricky Interview Questions & Answers | sql server interview question and answers
HTML-код
- Опубликовано: 20 фев 2020
- Top 6 SQL Tricky Interview Questions & Answers | Accenture SQL Interview Questions | Part 49
Top SQL interview questions and answers for freshers and professionals in 2021. These questions have been designed to help you become more comfortable with the types of questions you might be asked during your SQL interview.
Accenture SQL Questions and Answers 2020
Find Us On RUclips- "Subscribe Channel to watch Database related videos" / @ssunitech6890
For SQL Quiz-
• sql server : Interview...
Find Us On FaceBook-
/ ss-unitech-18770538867...
----Question--1
declare @input varchar(100)='abc,,,dddd,,,,,,dde,,2lmdl3emf,cewec,,,,,'
select @input,REPLACE(@input,',','.,'),replace(REPLACE(@input,',','.,'),',.',''),
replace(replace(REPLACE(@input,',','.,'),',.',''),'.,',',')
------Question--2
declare @source table(id int)
declare @dest table(id int)
insert @source values (1),(1)
select * from @source
Merge @dest as D
Using @Source as S
On s.id=d.id
When Matched Then
Update Set d.id=s.id
When Not Matched by Target then
Insert (id) Values (s.id);
select * from @dest
-------Question--3
SELECT LEN('SS UNITECH')-LEN(REPLACE('SS UNITECH','S',''))
-------Question--4
DECLARE @ATT TABLE (EMP INT,DATEPRESENT VARCHAR(50))
INSERT @ATT VALUES (1,'1,2,3'),(2,'2,4,5,6'),(3,'1,2,5,4,7,9')
SELECT *,LEN(DATEPRESENT)-LEN(REPLACE(DATEPRESENT,',','') )+1
FROM @ATT
-------Question--5
DECLARE @TBL TABLE(ID VARCHAR(100),NAME VARCHAR(100))
INSERT @TBL VALUES(1,'AA'),(2,'BB'),(3,'CC')
SELECT * FROM @TBL
UPDATE @TBL
SET ID=NAME,NAME=ID
SELECT * FROM @TBL
-------Question--6
DECLARE @I INT=100
;WITH CTE AS
(SELECT 1 AS ID
UNION ALL
SELECT ID+1
FROM CTE
WHERE ID
Very Informative and crispy. Appreciated and Thanks for sharing the knowledge.
Thanks for your appreciation.
Can you please share the videos to others?
Love this video.. thank you .. pls keep the good work going on
Thanks Sumit..
Please share to others.
Thanks
Wow it's great video and very helpful...
Hope you will upload more videos
Thanks Sandhya..
Nice video really helpful to get list of question and answer..
These are really very common question 2 questions were asked by me as well..
Keep it up..
Thanks Roshani..
Please create more videos like this , good work .....
Thanks Vipul..
Appreciate your efforts.. keep it up!!
Thanks for your appreciation
Nice explanation never seen before and ever after...
Nice to see your comment...
Thanks please share to others
To the point explanation... 👍Keep it up
Thanks for your appreciation 😘
Good work.. Thank you very much..
Thanks for your appreciation 😚
Great video...
Thanks
Very helpful...
Thanks for your appreciation
Thank you so much Sir ❤️❤️
Thanks 👍
Thank u for help
Thanks
very helpfull.
Thanks
Thanks for sharing
Thanks 👍
very nice video. Thank you
Thanks for your appreciation
Nyc videos
Thanks
Hello Sir, I think for length function question we can directly use length(replace()), no need to use - operator then again needs to add 1
Yes it may be, for a question we will have multiple solutions.
Thanks for your comment
Stay tuned and keep learning
can you pls give an example of that?
Short & Precise
Completely understood in 12 mins.
Request you to please upload some videos of C# use in SSIS.
Thanks Raj your continuous appreciation motivate me alot.. yes I have few scenarios where will use C# coding..
Thanks-SS Unitech
Nice video
Thanks Vaibhav
Nice
Thanks Vishnu .
For column swapping no need to update we can go with case statement like below
SELECT (CASE WHEN ID=ID THEN NAME END) AS ID,
(CASE WHEN NAME =NAME THEN ID END) AS NAME FROM TABLE NAME;
👍
Thanks for this. Very nice explanation - I Just thought, what if there are different combinations of number of commas existing in the Question. For Example - DECLARE @INPUT VARCHAR(100) = 'SAADD,,,,,,,,,,,,,SSFDSFDSF,,,,,,,SS,,SS,SS,,,SS,,,,,SS,,,,SS,,,,,,,,,,,,,,,,,,,,,S'. In such scenarios the below solution will be best fit - SELECT REPLACE(REPLACE(REPLACE(@INPUT , ',,,,' , ',') , ',,,' , ','), ',,', ',') - Just give a thought. All the best
Thanks for your suggestions
Hi Sir
can you please share the complete SQL classes, i have not found in playlist, if not please starts classes sir.
most of the interviews they are asking SQL logic quries.
I have don't have any playlist for SQL server tutorial. You can check SQL playlists there are 3 playlist. You can learn about query writing.
Thanks!
Could you please tell or make a video on recent accenture sql server application developer Online test and interview questions for 3 yers experience. It will be really helpful.
Sure.
Will do that
@@ssunitech6890 thank u for that. I have subscribed your channel. Could u please mail me some questions, actually I am having the interview on next monday, so I need it before that if possible 🙂
In channel, it's having around 60+ videos. Watch those videos
Second question regarding merge, first 1 will be not matched, so insert to destination, but 2nd 1 should be matched, thus it should be a update, so should it be only one row returns from @dest?
Thanks for your suggestions but your thinking is not right.
What I have explained is correct
Thanks for the tricky sql interview questions and answers...
for q4....select EMP, len(replace(DATEPRESENT,',',''))
from @ATT....
will also work?
Thanks for your appreciation.
Did you try this code?
Q5 :- How to swap the column if the ID is int and Name is varchar ??
Nope only swap if Id column is varchar.
If id is int then it will return an error.
Thanks
declare @name varchar(200) = 'SS aS UNITECH S'
select len(@name)- len( REPLACE( @name,'s',''))
Output : 5
Keep learning
NICE VIDEO...SIR HOW CAN I WRITE Q IF I HAVE TO FIND OCCURANCE OF S FROM 'NAME' COLUMN FROM TABLE --AND I HAVE TO STORE THAT RESULT
BCOZ THIS QUERY IS HARD CODED FOR 'SS UNITECH'
I GOT SOLUTION SIR THANKS
Sounds good.
Please share to others
SELECT NAME , LEN(NAME)AS TOTAL_LEN,
LEN(NAME)-LEN(REPLACE(NAME,'S','')) AS_LENGTH_OF_S_OCCOURANCE FROM OCCURANCE;
Nice
Len() also counts the blank space or not?
Yes Len() will count blank spaces.
Thanks
Hii sir plz give solution if id is int and name is varchar then how to swap in update statement
Hi Dhammasagar,
If you have int data type for id column then you can't swap it. It will return an error
Question: 'ABC, ,,,,,BCA,, ,, ,,CDB, ,, BTBGB,, ,,VEDR '
Ans:
declare @input2 varchar(100) = 'ABC, ,,,,,BCA,, ,, ,,CDB, ,, BTBGB,, ,,VEDR '
select REPLACE(REPLACE(REPLACE(@input2,',',' ,'),', ', ''),' ','')
Small modification based on your question Sir. Thank you.
Thanks 👍
Question 4, your answer only works when date presented is single digit numbers
I am thinking to use string_split function
It was introduced in later version of SQL server management studio.
That's why I didn't use it
this is the wrong login thing of scenario where instead of this 1,2,5,4,7,9 the data is 1,10,2,5,4,7,9 then if we need max number in DATEPRESENT
It's checking how many values are there not max value
Hello Sir..thanks for sharing this..I am from mostly support background having SQL and SSIS skills and I want to switch to SQL and ssis development ..ho can I achieve this
You can achieve it easily.
Watch SSIS videos on my channel.
Thanks
Dear sir I m a. Net developer but i want to get job in backend related work also with power bi... Along with. Net experience... But i m confuse how to crack interview what preparation i have to do... I want to get job base on sql and power bi... Pls guide
You have.net experience so first learn SQL server stored procedure, functions, triggers, views, temporary table and then start learning power bi data modeling.
@@ssunitech6890 Ok thank you...are these given topics enough to get new job? Because in interviews what question will come no idea... Please advice me... I m ready to do paid course of Power bi... From ur tranning. Ur teaching is superb
Stay tuned and keep learning
can u share project related interview question and answe
Project related SQL or SSIS interview questions and answers?
@@ssunitech6890 ptoject related in reference to ssis
Sure..
I have uploaded a video on SSIS project.
ruclips.net/video/PayvxG2om3s/видео.html
Please have a look and let me know
I think Q 5 should be wrong.
UPDATE @TBL
SET ID=NAME,NAME=ID
Once you set the ID column to have value of the NAME then the value of ID itself should be lost. Which means both columns now should have the NAME value.
Could you please help me (and other) on that.
Thank you.
In same query, you can replace it.
@@ssunitech6890 I am sorry. I did not understand. Could you please try once more ??
I noticed one major error in my initial post. Instead of "of" I had written "if".
Thank you.
for the third question,can't we use this ?
Select CHARINDEX('S','SS UNItech',2)
In this question: we are checking for occurance of the characters.
4th Question
Declare @ATT table (Emp int,Datepresent varchar(50))
insert @ATT Values(1,'1,2,3'),(2,'2,4,5,6'),(3,'1,2,5,4,7,9')
select emp, Len(replace(Datepresent,',',''))
from @ATT
Great man
Thanks
But it will not produce correct result if we have double digit dates like 11, 12,...etc.
Hope this works in your case Select emp, select count(*) from string_split(datepresent,',') from @ATT
Keep learning guys
Hello, I try this in MySQL and I cannot get it run. Is this cannot be processed in a new query tab in MySQL?
This query is used in SQL server
@@ssunitech6890 Thank you for a reply. Really love how you make SQL seems less difficult than it sounds :) All the best for you.
Thanks for your appreciation 😘
I mean, I don't have experience in MySQL, but you can not write in DB2.
Yes
at ruclips.net/video/VGj7_C-GD7E/видео.html the logic is incorrect in case of the 10th date.
On which question?
It is not dynamic lol
Which question lol?
@@ssunitech6890 1 st one
Hello Sir, I think for length function question we can directly use length(replace()), no need to use - operator then again needs to add 1
Yes it may be, for a question we will have multiple solutions.
Thanks for your comment
Stay tuned and keep learning
I have tried, it's working.
Great 👍