Question of the Week

From today onwards I have added a new section in my blog “Question of the Week”. In this section, I will be going to ask SQL puzzle twice a week from all of you and after two days will gives the answer for that Question. So keep answering:-)

Question on 25/12/2013 :-

Suppose we have a table says tbl_students whose structure is given below:-

Create table tbl_students(Studentid int identity(1,1) , Studentname nvarchar(150))

Suppose it contains the following data:-

Read More

Answer for Question asked on 25/12/2013



Question on 28/12/2013:-

Question:- Suppose we have a table named tbl_charactername have only one column say “charactername”.
It contains 10 rows. First 5 rows contains “Vivek Johari” and the next 5 rows contains “Abhinav Golwalkar”
tbl_charactername
———————
Vivek Johari
Vivek Johari
Vivek Johari
Vivek Johari
Vivek Johari
Abhinav Golwalkar
Abhinav Golwalkar
Abhinav Golwalkar
Abhinav Golwalkar
Abhinav Golwalkar
Now we need a SQL Query which can return the result in the form
Raad More..


Question of the Week -08/04/2014

Suppose we need to find out the name of all the months in a given year (Year will be given as an input parameter) where first day of the month falls on weekend (Saturday or Sunday). 
So what should be the query/stored procedure to get the above result?

DMCA.com

6 Responses to Question of the Week

  1. WITH CTE AS
    (
    SELECT 1 AS NUM UNION SELECT 3 UNION SELECT 4 UNION SELECT 8 UNION SELECT 10
    ),
    CTE1 AS
    (
    SELECT MIN(NUM) AS M,MAX(NUM) AS N FROM CTE
    UNION ALL
    SELECT M + 1,N FROM CTE1 WHERE M < N
    )
    SELECT M FROM CTE1 WHERE M NOT IN ( SELECT NUM FROM CTE )

  2. admin says:

    Hi Chetan
    Thanks for your response.
    But your answer is not giving the correct answer as it gives 2,5,6,7,9. The correct answer is 3,5,8,9.

    Again good going..

  3. Pawan says:

    Add some new puzzles 🙂

  4. Hi,
    Could you please suggest any Blogs and book for learning SSIS and SSRS.

  5. could you provide tricks for query execution plan.

  6. How can analysis DeadLock issue from " Deadlocks_0_13213.xel"
    file

Comments are closed.