Showing posts from January, 2016Show All
SQL Scenario based Interview Question and Answer - 4
SQL Scenario based Interview Question and Answer - 3
SQL Scenario based Interview Question and Answer - 2
SQL Scenario based Interview Question and Answer - 1

SQL Scenario based Interview Question and Answer - 4

 Problem Statement:-

Emp_Details Table has four columns EmpID, Gender, EmailID and DeptID. User has to write a SQL query to derive another column called Email_List to display all Emailid concatenated with semicolon associated with a each DEPT_ID as shown below in output Table.

INPUT:


OUTPUT:
 

Table and Insert SQL Script :
CREATE TABLE Emp_Details ( EMPID int, Gender varchar, EmailID varchar(30), DeptID int) INSERT INTO Emp_Details VALUES (1001,'M','YYYYY@gmaix.com',104) INSERT INTO Emp_Details VALUES (1002,'M','ZZZ@gmaix.com',103) INSERT INTO Emp_Details VALUES (1003,'F','AAAAA@gmaix.com',102) INSERT INTO Emp_Details VALUES (1004,'F','PP@gmaix.com',104) INSERT INTO Emp_Details VALUES (1005,'M','CCCC@yahu.com',101) INSERT INTO Emp_Details VALUES (1006,'M','DDDDD@yahu.com',100) INSERT INTO Emp_Details VALUES (1007,'F','E@yahu.com',102) INSERT INTO Emp_Details VALUES (1008,'M','M@yahu.com',102) INSERT INTO Emp_Details VALUES (1009,'F','SS@yahu.com',100)

Solution 1:
SELECT DeptID, STRING_AGG (EmailID,';') WITHIN GROUP ( ORDER BY EmailID) as Email_List FROM Emp_Details GROUP BY DeptID ORDER BY DeptID;

Solution 2:
  
SELECT DeptID, STUFF(( SELECT ';', CAST(EmailID AS VARCHAR(MAX)) FROM Emp_Details B WHERE A.DeptID=B.DeptID FOR XML PATH('') ), 1, 1, '') as Email_List FROM Emp_Details A GROUP BY DeptID ORDER BY DeptID;

SQL Scenario based Interview Question and Answer - 3

 Problem Statement :

Student Table has three columns Student_Name, Total_Marks and Year. User has to write a SQL query to display Student_Name, Total_Marks, Year, Prev_Yr_Marks for those whose Total_Marks are greater than or equal to the previous year.

INPUT:



OUTPUT :







Table and Insert SQL Script : CREATE TABLE Student( [Student_Name] varchar(30), [Total_Marks] int , [Year] int) INSERT INTO Student VALUES('Rahul',90,2010) INSERT INTO Student VALUES('Sanjay',80,2010) INSERT INTO Student VALUES('Mohan',70,2010) INSERT INTO Student VALUES('Rahul',90,2011) INSERT INTO Student VALUES('Sanjay',85,2011) INSERT INTO Student VALUES('Mohan',65,2011) INSERT INTO Student VALUES('Rahul',80,2012) INSERT INTO Student VALUES('Sanjay',80,2012) INSERT INTO Student VALUES('Mohan',90,2012)



Solution 1:

SELECT * FROM ( SELECT Student_Name, Total_Marks, Year, LAG(Total_Marks) OVER(PARTITION BY Student_Name ORDER BY Year ASC) Prev_Yr_Marks FROM Student ) as A WHERE Total_Marks>=Prev_Yr_Marks ORDER BY Year;

SQL Scenario based Interview Question and Answer - 2

 Problem Statement :

Given below table Emp as Input which has two columns 'Group' and 'Sequence'. Write a SQL query to find the maximum and minimum values of continuous ‘Sequence’ in each ‘Group’

INPUT:


OUTPUT:




Table and Insert SQL Script : CREATE TABLE Emp( [Group] varchar(20), [Sequence] int ) INSERT INTO Emp VALUES('A',1) INSERT INTO Emp VALUES('A',2) INSERT INTO Emp VALUES('A',3) INSERT INTO Emp VALUES('A',5) INSERT INTO Emp VALUES('A',6) INSERT INTO Emp VALUES('A',8) INSERT INTO Emp VALUES('A',9) INSERT INTO Emp VALUES('B',11) INSERT INTO Emp VALUES('C',1) INSERT INTO Emp VALUES('C',2) INSERT INTO Emp VALUES('C',3)


Solution 1:

; WITH DetailData as( SELECT [Group], [Sequence], ROW_NUMBER() OVER(PARTITION BY [GROUP] ORDER BY [Sequence]) as RN, [Sequence]- ROW_NUMBER() OVER(PARTITION BY [GROUP] ORDER BY [Sequence]) as Group_Split FROM Emp ) SELECT [Group], MIN([Sequence]) as Min_Sequence, MAX([Sequence]) as Max_Sequence FROM DetailData GROUP BY [Group], Group_Split ORDER BY [Group];

Solution 2:

SELECT [Group], MIN([Sequence]) as Min_Sequence, MAX([Sequence]) as Max_Sequence FROM ( SELECT [Group], [Sequence], ROW_NUMBER() OVER(PARTITION BY [GROUP] ORDER BY [Sequence]) as RN, [Sequence]- ROW_NUMBER() OVER(PARTITION BY [GROUP] ORDER BY [Sequence]) as Group_Split FROM Emp ) as A GROUP BY [Group], Group_Split ORDER BY [Group];

SQL Scenario based Interview Question and Answer - 1

 Problem Statement:-

Transatcion_tbl Table has four columns CustID, TranID, TranAmt, and TranDate. User has to display all these fields along with maximum TranAmt for each CustID and ratio of TranAmt and maximum TranAmt for each transaction.

INPUT:


EXPECTED OUTPUT:




Table and Insert Script _____________________________________________ CREATE TABLE [dbo].[Transaction_Tbl]( [CustID] [int] , [TranID] [int] , [TranAmt] [float] , [TranDate] [date] ) INSERT [dbo].[Transaction_Tbl] ([CustID], [TranID], [TranAmt], [TranDate]) VALUES (1001, 20001, 10000, CAST('2020-04-25' AS Date)) INSERT [dbo].[Transaction_Tbl] ([CustID], [TranID], [TranAmt], [TranDate]) VALUES (1001, 20002, 15000, CAST('2020-04-25' AS Date)) INSERT [dbo].[Transaction_Tbl] ([CustID], [TranID], [TranAmt], [TranDate]) VALUES (1001, 20003, 80000, CAST('2020-04-25' AS Date)) INSERT [dbo].[Transaction_Tbl] ([CustID], [TranID], [TranAmt], [TranDate]) VALUES (1001, 20004, 20000, CAST('2020-04-25' AS Date)) INSERT [dbo].[Transaction_Tbl] ([CustID], [TranID], [TranAmt], [TranDate]) VALUES (1002, 30001, 7000, CAST('2020-04-25' AS Date)) INSERT [dbo].[Transaction_Tbl] ([CustID], [TranID], [TranAmt], [TranDate]) VALUES (1002, 30002, 15000, CAST('2020-04-25' AS Date)) INSERT [dbo].[Transaction_Tbl] ([CustID], [TranID], [TranAmt], [TranDate]) VALUES (1002, 30003, 22000, CAST('2020-04-25' AS Date))

Solution 1:

select CustID, TranID, TranAmt, TranDate, MAX(TranAmt) OVER(PARTITION BY CustID ORDER BY TranAmt DESC) as MaxTranAmt, CAST((TranAmt/MAX(TranAmt) OVER(PARTITION BY CustID ORDER BY TranAmt DESC)) as DECIMAL(10,2)) as Ratio from [dbo].[Transaction_Tbl];

Solution 2:
select A.CustID, A.TranID, A.TranAmt, A.TranDate, B.MaxTranAmt, CAST((A.TranAmt/B.MaxTranAmt) as DECIMAL(10,2)) as Ratio from [dbo].[Transaction_Tbl] A INNER JOIN ( SELECT CustID, MAX(TranAmt) as MaxTranAmt FROM [dbo].[Transaction_Tbl] GROUP BY CustID ) as B ON A.CustID=B.CustID;

General Questions

Questions to be followed and ASK
DWH
1.Diff Star Schema and Snow Flake schema?
2.What is Fact less fact table?
3.what is Confirmed Dimension
  T-SQL 
1.How to insert values to the identity column in SQL Server?
2.Delete Duplicate Records from a table?
3.How To improve stored proc performance?
4.Types of joins?
5.Difference b/w CTE and temp tables?
6.what is outer apply and cross apply
7.index types and what is the cover index?
8.Difference between Stored Procedure and Function in SQL Server?

SSRS

1.How do u implement the Cascading parameter in SSRS?
2. How do u implement Multi value parameter in SSRS?
3.What is Drill through the report?
4.What is Subreport?
5.diff b/w Tablix and matrix report?
6.How to implement Report Security?
7. How to implement Report Subscription?
8.How to Show all records in single page in SSRS?
9.Show report header in all the pages in SSRS?

10.tell me critical report which you created in SSRS?

Unknown Company Interview Questions - 5

SQL:
  1. Describe the Join operations : What is the self join? Please explain in detail using one example.
  2. What is the difference between varchar & char data types?
  3. We had created the view using CTE, view performance is very poor. It will take around 15+ minutes to fetch the data. How to enhance the view performance?
  4. What types of indexes supported in SQL Server 2016?
  5. What are the new features in SQL Server 2016?
  6. Suppose we join around 10+ tables and query performance is very poor, how to check & optimize the query performance?
  7. Are you worked in Link Servers? If yes, please explain the same.
  8. How to monitor SQL Jobs using the SQL Queries or SQL Agent?
  9. Are you worked in complex stored procedure?
  10. What is the difference between stored procedure & function? Why we are using stored procedure? What are the benefits for the Stored Procedure?

SSIS :

  1. Describe the SSIS. Explain the flow how to create normal SSIS ETL Package?
  2. What are the data Transformations you used in ETL Packages? Explain in detail.
  3. Explain how to load Incremental data using SSIS tool?
  4. Difference between Merge Transformation & Lookup Transformation?
  5. Explain how to deploy the ETL packages using SSIS 2016?
  6. What are the new features in SSIS 2016?
  7. We deployed SSIS ETL package in SSIS Catalog & we created the job to execute the Package, suppose the Job is failed due to SSIS Package error, how you can check the error & resolve the same?
  8. How we check ETL errors using the SSIS catalog?
  9. In case of ETL Package failed, Should we trigger email with the ERROR description? If yes, Please explain in details.
  10. Explain Master & Child ETL Packages logic for loading the data.
  11. Suppose, In one SSIS package we are loading the data in 4 different tables. Suppose, 3 tables data is loaded successfully & 1 table data load is failed, If I again execute the package, we don't need to load again 3 tables data because the data is successfully loaded. We want to load the data which is failed during the execution. How we will achieve that? Please explain in details.

Unknown Company Interview Questions - 4

  1. Explain your role in Project?
  2. Explain your Project in detail

SSIS :
  1. What all transformations did you used?
  2. What is the difference between Merge and Union All?
  3. What is the difference between COPY Column and Derived Column?
  4. What are the different Container available in SSIS?
  5. How you have used lookup transformation? When to USe Full cache and Partial cache?
  6. Explain types of configuration in SSIS
  7. What is Checkpoint? How to use?
  8. Does Checkpoint work for FOREACH Loop? If not, what is an alternative solution?
  9. Difference between Control Flow and Data Flow?
  10. What is Precedence Constraints?
  11. What all connections you have used in your project?
  12. How you have handled error in our project?
  13. How to deploy SSIS package? Explain different types of Deployment.
  14. What is logging? How to use it?
  15. What is Transaction in SSIS?
  16. What is Synchronous and Asynchronous Transformation?
  17. What is execution tree?
  18. How to improve performance of SSIS packages?
  19. What are the features of SSIS latest version?
  20. Have you used Excel connection? Have you faced any challenges?
  21. What is Unicode, NonUnicode Strings? Excel source is UniCode or NonUnicode ?
  22. How to debug error if it occurs in Production environment?
  23. What are buffers in SSIS?
  24. How parallel execution works?
  25. Exception Handling in SSIS?
  26. Have you worked with SCD? How it works, explain in detail?
  27. What is the Fixed Attribute? If its fixed why it is called in SCD?
  28. How to schedule package using scheduler?
  29. If there are 100 files to load. We are using DFD task to load. If 96 files got correctly and task failed at 97 file. How will you handle? Do we need to load all files again?
  30. If we have trigger on Table for delete event. ANd we have used delete query in SSIS task? How it will work?
  31. We have below container containing 3 Tasks.( Task A, Task B and Task C).
  • All Tasks are running parallely. If tasks C fails in Between, what will happen? All tasks will stop? Container got fail?
  • How to handle this scenario?
  • On which task we need to create an event in event handler?
  1. Consider the above container is complete package, can we run this package parallely on same server?
  2. We have some excel and text files at one location and we need to load all these files into the same destination table. How to load both types of files from location into destination table?
SQL:
  1. What will be the output for table for all joins
Table A Table B
1 1
1 1
1 1
0 0
0 0
NULL NULL
  1. Error handling in stored procedure
  2. SQL 2012 features
  3. Types of Index and their uses?
  4. What is covering index?
  5. What is the use of CTE?
  6. Performance tuning in SQL query?
  7. Write different query to get below result from given table
Table:
EmpId
EmpName
ManagerID
1
A
2
2
B
3
3
C
NULL

Result:

EmpName
ManagerName
A
B
B
C
C
NULL

  1. Write result of All joins for below 2 Tables

Id
Name
1
A
2
B
3
A
3
C
NULL
D

Id
Name
2
A
2
A
3
B
4
C
5
D

  1. Consider the above tables A & B. Check the id of Table A with Table B. If id matches then update Name of table B with table A value
  2. How to show error message in SQL Server?
  3. What is Trigger? How it works?
  4. What is Normalisation? Explain different types of Normalisation.
  5. If we have simple insert statement in Stored Procedure. Which method give faster results? Executing STored Procedure or Direct Insert Statement?
  6. What is MErge in SQl? How to use it?
  7. What is view? Can we create index on view?
  8. What is transaction?
  9. Difference between Stored Procedure and Function
  10. What is Primary Key and Foriegn Key?
  11. What is Unique Key? Can we handle NULL data in Unique Key?
  12. Can we delete records from view created on 2 tables?
  13. What is Execution Plan? When and How to use it?
  14. EmpSales:

id
name
add
sal
1
A
xyz
2000
2
B
pqr
3000

EmpAcc:

id
name
add
sal
1
A
xyz
2000
2
B
pqr
3000

What will the result of below query:
SELECT id, name, add, sal FROM EmpSales
UNION
SELECT id, name, sal, add FROM EmpAcc

  1. How to remove duplicate records from table?
  2. What is the difference between Temp Table and CTE?
  3. Can we pass table as a Parameter to Stored Procedure? If YEs, How to pass it?
  4. Can we call stored procedure inside another stored procedure?
  5. Table A:

id
name 
sal
1
A
200
2
B
300
3
C
400
Write query to get below output?

id
Name
sal
New column
1
A
200
200
2
B
300
500
3
C
400
900


id
Name
sal
New column
1
A
200
300
2
B
300
400
3
C
400
NULL

  1. How to execute stored procedure with output parameter?
  2. What is ROW_NUMBER(), RANK() and DENSE_RANK() function?
  3. Can we use DML statement on views?
  4. What is the use of Cross Join? Explain with example
  5. What is meant by Business Key and Surrogate Key? What is the difference between them?
  6. Can I delete record from view?
  7. What happen in background when we fire “select * from tablename” query?
SSRS:
  1. What types of reports you have created in your project?
  2. What is cascade parameter report?
  3. How to create drill down report?
  4. How to deploy report?
  5. What is report subscription?
  6. Can we use stored procedure in SSRS report?
  7. What is report server and report manager?