# 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:-

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

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?

## 6 thoughts on “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. Hi Chetan

Again good going..

3. 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.