<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
		>
<channel>
	<title>Comments on: SQL SERVER &#8211; Interesting Interview Questions</title>
	<atom:link href="http://blog.sqlauthority.com/2008/12/07/sql-server-interesting-interview-questions/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.sqlauthority.com/2008/12/07/sql-server-interesting-interview-questions/</link>
	<description>Personal Notes of Pinal Dave</description>
	<lastBuildDate>Thu, 23 May 2013 14:22:59 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
	<item>
		<title>By: SQL SERVER &#8211; Weekly Series &#8211; Memory Lane &#8211; #008 &#171; SQL Server Journey with SQL Authority</title>
		<link>http://blog.sqlauthority.com/2008/12/07/sql-server-interesting-interview-questions/#comment-397385</link>
		<dc:creator><![CDATA[SQL SERVER &#8211; Weekly Series &#8211; Memory Lane &#8211; #008 &#171; SQL Server Journey with SQL Authority]]></dc:creator>
		<pubDate>Sat, 22 Dec 2012 01:31:49 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=1624#comment-397385</guid>
		<description><![CDATA[[...] Interview Questions – Revisited Read Interesting Interview Questions before continuing reading this article. This interview question was about user participation and [...]]]></description>
		<content:encoded><![CDATA[<p>[...] Interview Questions – Revisited Read Interesting Interview Questions before continuing reading this article. This interview question was about user participation and [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Nikash</title>
		<link>http://blog.sqlauthority.com/2008/12/07/sql-server-interesting-interview-questions/#comment-293777</link>
		<dc:creator><![CDATA[Nikash]]></dc:creator>
		<pubDate>Mon, 04 Jun 2012 13:44:37 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=1624#comment-293777</guid>
		<description><![CDATA[select &#039;student1 has&#039;+ CONVERT(varchar(10), SUM(class1) )+&#039;staudent&#039;
from StudentsEnroll

union all

select &#039;student2 has&#039;+ CONVERT(varchar(10), SUM(class2) ) +&#039;staudent&#039;
from StudentsEnroll

union all

select &#039;student3 has&#039;+ CONVERT(varchar(10), SUM(class3))  +&#039;staudent&#039;
from StudentsEnroll]]></description>
		<content:encoded><![CDATA[<p>select &#8216;student1 has&#8217;+ CONVERT(varchar(10), SUM(class1) )+&#8217;staudent&#8217;<br />
from StudentsEnroll</p>
<p>union all</p>
<p>select &#8216;student2 has&#8217;+ CONVERT(varchar(10), SUM(class2) ) +&#8217;staudent&#8217;<br />
from StudentsEnroll</p>
<p>union all</p>
<p>select &#8216;student3 has&#8217;+ CONVERT(varchar(10), SUM(class3))  +&#8217;staudent&#8217;<br />
from StudentsEnroll</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: INDIA</title>
		<link>http://blog.sqlauthority.com/2008/12/07/sql-server-interesting-interview-questions/#comment-93192</link>
		<dc:creator><![CDATA[INDIA]]></dc:creator>
		<pubDate>Fri, 15 Oct 2010 09:19:44 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=1624#comment-93192</guid>
		<description><![CDATA[thanks pinal for providing good platform for learing 
sql

this site very helpful for me

keep it up......]]></description>
		<content:encoded><![CDATA[<p>thanks pinal for providing good platform for learing<br />
sql</p>
<p>this site very helpful for me</p>
<p>keep it up&#8230;&#8230;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: INDIA</title>
		<link>http://blog.sqlauthority.com/2008/12/07/sql-server-interesting-interview-questions/#comment-93191</link>
		<dc:creator><![CDATA[INDIA]]></dc:creator>
		<pubDate>Fri, 15 Oct 2010 09:17:07 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=1624#comment-93191</guid>
		<description><![CDATA[declare @total int 
 set @total =0
 select &#039;CLASS 1 HAS &#039; + case  when class1=1  then CAST (SUM(@total+1)AS VARCHAR(10)) + &#039; STUDENTS&#039; end  from StudentsEnroll 
 WHERE Class1 =1
 group by Class1  
 UNION ALL

 select &#039;CLASS 2 HAS &#039; + case  when class2=1  then CAST (SUM(@total+1)AS VARCHAR(10)) + &#039; STUDENTS&#039; end  from StudentsEnroll 
 WHERE Class2 =1
 group by Class2  
 
 UNION ALL

 select &#039;CLASS 3 HAS &#039; + case  when class3=1  then CAST (SUM(@total+1)AS VARCHAR(10)) + &#039; STUDENTS&#039; end  from StudentsEnroll 
 WHERE Class3 =1
 group by Class3]]></description>
		<content:encoded><![CDATA[<p>declare @total int<br />
 set @total =0<br />
 select &#8216;CLASS 1 HAS &#8216; + case  when class1=1  then CAST (SUM(@total+1)AS VARCHAR(10)) + &#8216; STUDENTS&#8217; end  from StudentsEnroll<br />
 WHERE Class1 =1<br />
 group by Class1<br />
 UNION ALL</p>
<p> select &#8216;CLASS 2 HAS &#8216; + case  when class2=1  then CAST (SUM(@total+1)AS VARCHAR(10)) + &#8216; STUDENTS&#8217; end  from StudentsEnroll<br />
 WHERE Class2 =1<br />
 group by Class2  </p>
<p> UNION ALL</p>
<p> select &#8216;CLASS 3 HAS &#8216; + case  when class3=1  then CAST (SUM(@total+1)AS VARCHAR(10)) + &#8216; STUDENTS&#8217; end  from StudentsEnroll<br />
 WHERE Class3 =1<br />
 group by Class3</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Lopa</title>
		<link>http://blog.sqlauthority.com/2008/12/07/sql-server-interesting-interview-questions/#comment-60104</link>
		<dc:creator><![CDATA[Lopa]]></dc:creator>
		<pubDate>Fri, 22 Jan 2010 15:03:00 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=1624#comment-60104</guid>
		<description><![CDATA[Probably I&#039;m asking this doubt very late.

You asked to write a query about student enrollment where there are three classes ; Class1 , Class2 and Class3 and 4 students as Student1, Student2, Student3 and Student4. And there is a table StudentEnroll which has the data which depicts which student is enrolled to which class.

The format of the output should be The Class 1 has 3 students and so on; for all the classes.

You have provided the followin solution

DECLARE @Col INT
SET @Col = 1
WHILE (@Col &lt; 4)
BEGIN
EXEC(&#039;SELECT     &#039;&#039;Class&#039;+@Col+&#039; Has &#039;&#039; + CAST(COUNT(Students) AS VARCHAR(100)) + &#039;&#039; Students&#039;&#039; Results
FROM         studentsenroll
WHERE         Class&#039;+@Col+&#039; = 1
GROUP BY      Class&#039;+@Col)
SET @Col = @Col + 1
CONTINUE
END 

Now, I can understand that you are considering only those students who have been enrolled and that&#039;s the reason the class&#039;+@col+&#039; = 1 is a constant value.

This can be easily done by using the Sum function.  But, you have mentioned that if the scenario is dynamic then we have to use the Group By function. Could you please explain me the Dynamic scenario.

I&#039;m sorry if I sound stupid.

Regards,
Lopa]]></description>
		<content:encoded><![CDATA[<p>Probably I&#8217;m asking this doubt very late.</p>
<p>You asked to write a query about student enrollment where there are three classes ; Class1 , Class2 and Class3 and 4 students as Student1, Student2, Student3 and Student4. And there is a table StudentEnroll which has the data which depicts which student is enrolled to which class.</p>
<p>The format of the output should be The Class 1 has 3 students and so on; for all the classes.</p>
<p>You have provided the followin solution</p>
<p>DECLARE @Col INT<br />
SET @Col = 1<br />
WHILE (@Col &lt; 4)<br />
BEGIN<br />
EXEC(&#039;SELECT     &#039;&#039;Class&#039;+@Col+&#039; Has &#039;&#039; + CAST(COUNT(Students) AS VARCHAR(100)) + &#039;&#039; Students&#039;&#039; Results<br />
FROM         studentsenroll<br />
WHERE         Class&#039;+@Col+&#039; = 1<br />
GROUP BY      Class&#039;+@Col)<br />
SET @Col = @Col + 1<br />
CONTINUE<br />
END </p>
<p>Now, I can understand that you are considering only those students who have been enrolled and that&#039;s the reason the class&#039;+@col+&#039; = 1 is a constant value.</p>
<p>This can be easily done by using the Sum function.  But, you have mentioned that if the scenario is dynamic then we have to use the Group By function. Could you please explain me the Dynamic scenario.</p>
<p>I&#039;m sorry if I sound stupid.</p>
<p>Regards,<br />
Lopa</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Pinal Dave</title>
		<link>http://blog.sqlauthority.com/2008/12/07/sql-server-interesting-interview-questions/#comment-60086</link>
		<dc:creator><![CDATA[Pinal Dave]]></dc:creator>
		<pubDate>Fri, 22 Jan 2010 10:29:27 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=1624#comment-60086</guid>
		<description><![CDATA[Hi Lopa,

In expression class + &#039;@col&#039; what is class and what is value in @col? Please provide details about your query.

Regards,
Pinal Dave]]></description>
		<content:encoded><![CDATA[<p>Hi Lopa,</p>
<p>In expression class + &#8216;@col&#8217; what is class and what is value in @col? Please provide details about your query.</p>
<p>Regards,<br />
Pinal Dave</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Lopa</title>
		<link>http://blog.sqlauthority.com/2008/12/07/sql-server-interesting-interview-questions/#comment-60062</link>
		<dc:creator><![CDATA[Lopa]]></dc:creator>
		<pubDate>Thu, 21 Jan 2010 23:27:20 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=1624#comment-60062</guid>
		<description><![CDATA[Hi  Pinal,

You are doing a great job.

I may sound low, but could you please explain me the where clause of the above query. Why the class+&#039;@col&#039; value is always constant?

Thanks,
Lopa]]></description>
		<content:encoded><![CDATA[<p>Hi  Pinal,</p>
<p>You are doing a great job.</p>
<p>I may sound low, but could you please explain me the where clause of the above query. Why the class+&#8217;@col&#8217; value is always constant?</p>
<p>Thanks,<br />
Lopa</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Sandor</title>
		<link>http://blog.sqlauthority.com/2008/12/07/sql-server-interesting-interview-questions/#comment-58205</link>
		<dc:creator><![CDATA[Sandor]]></dc:creator>
		<pubDate>Fri, 04 Dec 2009 19:44:38 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=1624#comment-58205</guid>
		<description><![CDATA[How about this:

select classname + &#039; has &#039; + Cast(total As Nvarchar(2)) + &#039; students&#039; from
(
select
	sum(class1) class1,
	sum(class2) class2,
	sum(class3) class3
from studentsenroll
) p
unpivot
( Total for classname in (class1,class2,class3)) as S]]></description>
		<content:encoded><![CDATA[<p>How about this:</p>
<p>select classname + &#8216; has &#8216; + Cast(total As Nvarchar(2)) + &#8216; students&#8217; from<br />
(<br />
select<br />
	sum(class1) class1,<br />
	sum(class2) class2,<br />
	sum(class3) class3<br />
from studentsenroll<br />
) p<br />
unpivot<br />
( Total for classname in (class1,class2,class3)) as S</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: RakeshA</title>
		<link>http://blog.sqlauthority.com/2008/12/07/sql-server-interesting-interview-questions/#comment-56019</link>
		<dc:creator><![CDATA[RakeshA]]></dc:creator>
		<pubDate>Mon, 21 Sep 2009 17:19:24 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=1624#comment-56019</guid>
		<description><![CDATA[create table xs(sname nvarchar(5),class1 int,class2 int,class3 int)


insert into xs values(&#039;stu1&#039;,1,0,1)
insert into xs values(&#039;stu2&#039;,1,0,1)
insert into xs values(&#039;stu3&#039;,0,1,0)
insert into xs values(&#039;stu4&#039;,1,0,1)


select sname+&#039;has &#039;+ cast((class1+class2+class3) as nvarchar(10))+&#039;students&#039; from xs]]></description>
		<content:encoded><![CDATA[<p>create table xs(sname nvarchar(5),class1 int,class2 int,class3 int)</p>
<p>insert into xs values(&#8216;stu1&#8242;,1,0,1)<br />
insert into xs values(&#8216;stu2&#8242;,1,0,1)<br />
insert into xs values(&#8216;stu3&#8242;,0,1,0)<br />
insert into xs values(&#8216;stu4&#8242;,1,0,1)</p>
<p>select sname+&#8217;has &#8216;+ cast((class1+class2+class3) as nvarchar(10))+&#8217;students&#8217; from xs</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Kode</title>
		<link>http://blog.sqlauthority.com/2008/12/07/sql-server-interesting-interview-questions/#comment-52899</link>
		<dc:creator><![CDATA[Kode]]></dc:creator>
		<pubDate>Wed, 10 Jun 2009 09:14:28 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=1624#comment-52899</guid>
		<description><![CDATA[declare @count int
declare @name varchar(30)
declare @stmt nvarchar(500)
set @stmt = &#039;&#039;
select @count = count(*) from sys.columns where object_id = object_id(&#039;studentsenroll&#039;) and name  &#039;Students&#039;
Declare c1 cursor 
For select Name From sys.columns where object_id = object_id(&#039;studentsenroll&#039;) and name  &#039;Students&#039;
Open c1 
fetch next from c1 into @name
while @@fetch_status = 0
Begin
if ( @count &gt; 1)
	set @stmt = @stmt +  &#039;select &#039;&#039;&#039; + @name + &#039; has &#039;&#039; +  cast(sum(cast(&#039; + @name + &#039; as int)) as varchar) +&#039;&#039; students &#039;&#039;  From studentsenroll union all &#039;
else
	set @stmt = @stmt +  &#039;select &#039;&#039;&#039; + @name + &#039; has &#039;&#039; +  cast(sum(cast(&#039; + @name + &#039; as int)) as varchar) +&#039;&#039; students &#039;&#039;  From studentsenroll &#039;
SET @count = @count-1
fetch next from c1 into @name
End
exec sp_executesql @stmt
close c1
deallocate c1]]></description>
		<content:encoded><![CDATA[<p>declare @count int<br />
declare @name varchar(30)<br />
declare @stmt nvarchar(500)<br />
set @stmt = &#8221;<br />
select @count = count(*) from sys.columns where object_id = object_id(&#8216;studentsenroll&#8217;) and name  &#8216;Students&#8217;<br />
Declare c1 cursor<br />
For select Name From sys.columns where object_id = object_id(&#8216;studentsenroll&#8217;) and name  &#8216;Students&#8217;<br />
Open c1<br />
fetch next from c1 into @name<br />
while @@fetch_status = 0<br />
Begin<br />
if ( @count &gt; 1)<br />
	set @stmt = @stmt +  &#8216;select &#8221;&#8217; + @name + &#8216; has &#8221; +  cast(sum(cast(&#8216; + @name + &#8216; as int)) as varchar) +&#8221; students &#8221;  From studentsenroll union all &#8216;<br />
else<br />
	set @stmt = @stmt +  &#8216;select &#8221;&#8217; + @name + &#8216; has &#8221; +  cast(sum(cast(&#8216; + @name + &#8216; as int)) as varchar) +&#8221; students &#8221;  From studentsenroll &#8216;<br />
SET @count = @count-1<br />
fetch next from c1 into @name<br />
End<br />
exec sp_executesql @stmt<br />
close c1<br />
deallocate c1</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Anu</title>
		<link>http://blog.sqlauthority.com/2008/12/07/sql-server-interesting-interview-questions/#comment-52053</link>
		<dc:creator><![CDATA[Anu]]></dc:creator>
		<pubDate>Tue, 19 May 2009 11:46:53 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=1624#comment-52053</guid>
		<description><![CDATA[Hi Pinal,
This place is really gud for all the issues related to sql.
I just saw the query above so just tried this way


select &#039;Class1 has &#039; + cast(count(nullif(class1,0))as varchar(10))  +&#039; students&#039; from StudentsEnroll union
select &#039;Class2 has &#039;+ cast(count(nullif(class2,0))as varchar(10)) + &#039; students&#039; from StudentsEnroll union
select &#039;Class3 has &#039;+cast(count(nullif(class3,0))as varchar(10))  +&#039; students&#039;from StudentsEnroll 



Its the same way as you have written i have just modified the query by using NULLIF so where clause would&#039;nt be used.]]></description>
		<content:encoded><![CDATA[<p>Hi Pinal,<br />
This place is really gud for all the issues related to sql.<br />
I just saw the query above so just tried this way</p>
<p>select &#8216;Class1 has &#8216; + cast(count(nullif(class1,0))as varchar(10))  +&#8217; students&#8217; from StudentsEnroll union<br />
select &#8216;Class2 has &#8216;+ cast(count(nullif(class2,0))as varchar(10)) + &#8216; students&#8217; from StudentsEnroll union<br />
select &#8216;Class3 has &#8216;+cast(count(nullif(class3,0))as varchar(10))  +&#8217; students&#8217;from StudentsEnroll </p>
<p>Its the same way as you have written i have just modified the query by using NULLIF so where clause would&#8217;nt be used.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jerry</title>
		<link>http://blog.sqlauthority.com/2008/12/07/sql-server-interesting-interview-questions/#comment-45345</link>
		<dc:creator><![CDATA[Jerry]]></dc:creator>
		<pubDate>Mon, 05 Jan 2009 07:14:04 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=1624#comment-45345</guid>
		<description><![CDATA[Hi Pinal,

I am a beginner in SQL can you please give me suggestion as to how i can improve on it?.
I am very much interested in learning SQL Server.

Thanks,
Jerry]]></description>
		<content:encoded><![CDATA[<p>Hi Pinal,</p>
<p>I am a beginner in SQL can you please give me suggestion as to how i can improve on it?.<br />
I am very much interested in learning SQL Server.</p>
<p>Thanks,<br />
Jerry</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: meh</title>
		<link>http://blog.sqlauthority.com/2008/12/07/sql-server-interesting-interview-questions/#comment-44919</link>
		<dc:creator><![CDATA[meh]]></dc:creator>
		<pubDate>Thu, 18 Dec 2008 21:04:43 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=1624#comment-44919</guid>
		<description><![CDATA[SELECT 
	UP.Class + &#039; has &#039; + CONVERT(varchar, SUM(CONVERT(int, UP.Total))) + &#039; Students&#039; [Output] 
FROM 
	(
		SELECT 
			Students [Enrolled], 
			Class1, 
			Class2, 
			Class3 
		FROM 
			StudentsEnroll 
	) SE 
	UNPIVOT (Total FOR Class IN (Class1, Class2, Class3)) UP 
GROUP BY 
	UP.Class]]></description>
		<content:encoded><![CDATA[<p>SELECT<br />
	UP.Class + &#8216; has &#8216; + CONVERT(varchar, SUM(CONVERT(int, UP.Total))) + &#8216; Students&#8217; [Output]<br />
FROM<br />
	(<br />
		SELECT<br />
			Students [Enrolled],<br />
			Class1,<br />
			Class2,<br />
			Class3<br />
		FROM<br />
			StudentsEnroll<br />
	) SE<br />
	UNPIVOT (Total FOR Class IN (Class1, Class2, Class3)) UP<br />
GROUP BY<br />
	UP.Class</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: cvdev</title>
		<link>http://blog.sqlauthority.com/2008/12/07/sql-server-interesting-interview-questions/#comment-44894</link>
		<dc:creator><![CDATA[cvdev]]></dc:creator>
		<pubDate>Wed, 17 Dec 2008 20:51:57 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=1624#comment-44894</guid>
		<description><![CDATA[SELECT &#039;Class1 Has &#039;+CAST(SUM(CAST(Class1 AS INT)) AS VARCHAR(10))+&#039; Students&#039;+CHAR(10)+
	   &#039;Class2 Has &#039;+CAST(SUM(CAST(Class2 AS INT)) AS VARCHAR(10))+&#039; Students&#039;+CHAR(10)+
	   &#039;Class3 Has &#039;+CAST(SUM(CAST(Class3 AS INT)) AS VARCHAR(10))+&#039; Students&#039;+CHAR(10)
 FROM [StudentsEnroll]]]></description>
		<content:encoded><![CDATA[<p>SELECT &#8216;Class1 Has &#8216;+CAST(SUM(CAST(Class1 AS INT)) AS VARCHAR(10))+&#8217; Students&#8217;+CHAR(10)+<br />
	   &#8216;Class2 Has &#8216;+CAST(SUM(CAST(Class2 AS INT)) AS VARCHAR(10))+&#8217; Students&#8217;+CHAR(10)+<br />
	   &#8216;Class3 Has &#8216;+CAST(SUM(CAST(Class3 AS INT)) AS VARCHAR(10))+&#8217; Students&#8217;+CHAR(10)<br />
 FROM [StudentsEnroll]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Harshal</title>
		<link>http://blog.sqlauthority.com/2008/12/07/sql-server-interesting-interview-questions/#comment-44878</link>
		<dc:creator><![CDATA[Harshal]]></dc:creator>
		<pubDate>Wed, 17 Dec 2008 11:13:48 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=1624#comment-44878</guid>
		<description><![CDATA[SELECT &#039;Class1 has &#039;+ CONVERT(nvarchar(10),sum(CASE class1 WHEN 1 THEN 1 ELSE 0 end))+&#039; students&#039; 
FROM StudentsEnroll se union ALL
SELECT &#039;Class2 has &#039;+ CONVERT(nvarchar(10),sum(CASE class2 WHEN 1 THEN 1 ELSE 0 end))+&#039; students&#039; 
FROM StudentsEnroll se union ALL
SELECT &#039;Class3 has &#039;+ CONVERT(nvarchar(10),sum(CASE class3 WHEN 1 THEN 1 ELSE 0 end))+&#039; students&#039; 
FROM StudentsEnroll se]]></description>
		<content:encoded><![CDATA[<p>SELECT &#8216;Class1 has &#8216;+ CONVERT(nvarchar(10),sum(CASE class1 WHEN 1 THEN 1 ELSE 0 end))+&#8217; students&#8217;<br />
FROM StudentsEnroll se union ALL<br />
SELECT &#8216;Class2 has &#8216;+ CONVERT(nvarchar(10),sum(CASE class2 WHEN 1 THEN 1 ELSE 0 end))+&#8217; students&#8217;<br />
FROM StudentsEnroll se union ALL<br />
SELECT &#8216;Class3 has &#8216;+ CONVERT(nvarchar(10),sum(CASE class3 WHEN 1 THEN 1 ELSE 0 end))+&#8217; students&#8217;<br />
FROM StudentsEnroll se</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: SQL SERVER - Interesting Interview Questions - Revisited Journey to SQL Authority with Pinal Dave</title>
		<link>http://blog.sqlauthority.com/2008/12/07/sql-server-interesting-interview-questions/#comment-44863</link>
		<dc:creator><![CDATA[SQL SERVER - Interesting Interview Questions - Revisited Journey to SQL Authority with Pinal Dave]]></dc:creator>
		<pubDate>Wed, 17 Dec 2008 01:30:29 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=1624#comment-44863</guid>
		<description><![CDATA[[...] Zod [...]]]></description>
		<content:encoded><![CDATA[<p>[...] Zod [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: jagadesh</title>
		<link>http://blog.sqlauthority.com/2008/12/07/sql-server-interesting-interview-questions/#comment-44730</link>
		<dc:creator><![CDATA[jagadesh]]></dc:creator>
		<pubDate>Thu, 11 Dec 2008 14:44:12 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=1624#comment-44730</guid>
		<description><![CDATA[hi pinal,
I am a beginner in sql server...can u give me any suggestions in his regard..


Thanks 
Jagadesh]]></description>
		<content:encoded><![CDATA[<p>hi pinal,<br />
I am a beginner in sql server&#8230;can u give me any suggestions in his regard..</p>
<p>Thanks<br />
Jagadesh</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: jagadesh</title>
		<link>http://blog.sqlauthority.com/2008/12/07/sql-server-interesting-interview-questions/#comment-44729</link>
		<dc:creator><![CDATA[jagadesh]]></dc:creator>
		<pubDate>Thu, 11 Dec 2008 14:40:17 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=1624#comment-44729</guid>
		<description><![CDATA[hi i am new to sql server and its very intresting to see such good questions.
i would participate int hese discussions and post my comments for the queries.

Thanks
jagadesh]]></description>
		<content:encoded><![CDATA[<p>hi i am new to sql server and its very intresting to see such good questions.<br />
i would participate int hese discussions and post my comments for the queries.</p>
<p>Thanks<br />
jagadesh</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: mumu</title>
		<link>http://blog.sqlauthority.com/2008/12/07/sql-server-interesting-interview-questions/#comment-44715</link>
		<dc:creator><![CDATA[mumu]]></dc:creator>
		<pubDate>Thu, 11 Dec 2008 04:45:24 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=1624#comment-44715</guid>
		<description><![CDATA[Imran is correct in that PIVOT is not the answer (as surmised) but UNPIVOT.

Here&#039;s a bit cleaner version of UNPIVOT that is closer to the asked for end result...

SELECT Class,  
	CAST(&#039;has&#039; as char(3)) as &#039;has&#039;, 
	SUM(CAST(Breakout as tinyint)) as &#039;X&#039;, 
	CAST(&#039;students.&#039; as char(9)) as &#039;students.&#039;
FROM (

SELECT Class, Breakout, Students FROM 
(
	SELECT Students, Class1, Class2, Class3
	FROM StudentsEnroll 
) se_inner
UNPIVOT	(Breakout FOR Class IN (Class1, Class2, Class3)) AS denorm
) se_outer
GROUP BY Class ORDER BY Class]]></description>
		<content:encoded><![CDATA[<p>Imran is correct in that PIVOT is not the answer (as surmised) but UNPIVOT.</p>
<p>Here&#8217;s a bit cleaner version of UNPIVOT that is closer to the asked for end result&#8230;</p>
<p>SELECT Class,<br />
	CAST(&#8216;has&#8217; as char(3)) as &#8216;has&#8217;,<br />
	SUM(CAST(Breakout as tinyint)) as &#8216;X&#8217;,<br />
	CAST(&#8216;students.&#8217; as char(9)) as &#8216;students.&#8217;<br />
FROM (</p>
<p>SELECT Class, Breakout, Students FROM<br />
(<br />
	SELECT Students, Class1, Class2, Class3<br />
	FROM StudentsEnroll<br />
) se_inner<br />
UNPIVOT	(Breakout FOR Class IN (Class1, Class2, Class3)) AS denorm<br />
) se_outer<br />
GROUP BY Class ORDER BY Class</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: pinaldave</title>
		<link>http://blog.sqlauthority.com/2008/12/07/sql-server-interesting-interview-questions/#comment-44701</link>
		<dc:creator><![CDATA[pinaldave]]></dc:creator>
		<pubDate>Wed, 10 Dec 2008 20:06:23 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=1624#comment-44701</guid>
		<description><![CDATA[Guys, this is great participation from all of you, I will be writing in depth another article where I will have all this answers included.

Keep up the good work. 

If you are interested participate in second question : 
http://blog.sqlauthority.com/2008/12/10/sql-server-interesting-interview-questions-part-2-puzzle/


Regards,
Pinal Dave ( http://blog.sqlauthority.com )]]></description>
		<content:encoded><![CDATA[<p>Guys, this is great participation from all of you, I will be writing in depth another article where I will have all this answers included.</p>
<p>Keep up the good work. </p>
<p>If you are interested participate in second question :<br />
<a href="http://blog.sqlauthority.com/2008/12/10/sql-server-interesting-interview-questions-part-2-puzzle/" rel="nofollow">http://blog.sqlauthority.com/2008/12/10/sql-server-interesting-interview-questions-part-2-puzzle/</a></p>
<p>Regards,<br />
Pinal Dave ( <a href="http://blog.sqlauthority.com" rel="nofollow">http://blog.sqlauthority.com</a> )</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Prabhat</title>
		<link>http://blog.sqlauthority.com/2008/12/07/sql-server-interesting-interview-questions/#comment-44655</link>
		<dc:creator><![CDATA[Prabhat]]></dc:creator>
		<pubDate>Tue, 09 Dec 2008 18:14:41 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=1624#comment-44655</guid>
		<description><![CDATA[Thanks for the nice tricks.]]></description>
		<content:encoded><![CDATA[<p>Thanks for the nice tricks.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: pom</title>
		<link>http://blog.sqlauthority.com/2008/12/07/sql-server-interesting-interview-questions/#comment-44629</link>
		<dc:creator><![CDATA[pom]]></dc:creator>
		<pubDate>Tue, 09 Dec 2008 06:01:07 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=1624#comment-44629</guid>
		<description><![CDATA[select &#039;class1 has &#039; + cast((select count(*) from StudentsEnroll where class1=1 group by class1) as char(3)) + &#039;Students&#039;
union
select &#039;class2 has &#039; + cast((select count(*) from StudentsEnroll where class2=1 group by class2) as char(3)) + &#039;Students&#039;
union
select &#039;class3 has &#039; + cast((select count(*) from StudentsEnroll where class3=1 group by class3) as char(3)) + &#039;Students&#039;]]></description>
		<content:encoded><![CDATA[<p>select &#8216;class1 has &#8216; + cast((select count(*) from StudentsEnroll where class1=1 group by class1) as char(3)) + &#8216;Students&#8217;<br />
union<br />
select &#8216;class2 has &#8216; + cast((select count(*) from StudentsEnroll where class2=1 group by class2) as char(3)) + &#8216;Students&#8217;<br />
union<br />
select &#8216;class3 has &#8216; + cast((select count(*) from StudentsEnroll where class3=1 group by class3) as char(3)) + &#8216;Students&#8217;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: SQL SERVER - Find Table Rowcount Without Using T-SQL and Without Opening Table Journey to SQL Authority with Pinal Dave</title>
		<link>http://blog.sqlauthority.com/2008/12/07/sql-server-interesting-interview-questions/#comment-44622</link>
		<dc:creator><![CDATA[SQL SERVER - Find Table Rowcount Without Using T-SQL and Without Opening Table Journey to SQL Authority with Pinal Dave]]></dc:creator>
		<pubDate>Tue, 09 Dec 2008 01:31:29 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=1624#comment-44622</guid>
		<description><![CDATA[[...] December 9, 2008 by pinaldave    Recently I have been busy with interviewing many candidates for my organization. We are looking for some smart and experienced developers for some senior positions. I have wrote this previously SQL SERVER - Interesting Interview Questions. [...]]]></description>
		<content:encoded><![CDATA[<p>[...] December 9, 2008 by pinaldave    Recently I have been busy with interviewing many candidates for my organization. We are looking for some smart and experienced developers for some senior positions. I have wrote this previously SQL SERVER &#8211; Interesting Interview Questions. [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Prakash</title>
		<link>http://blog.sqlauthority.com/2008/12/07/sql-server-interesting-interview-questions/#comment-44617</link>
		<dc:creator><![CDATA[Prakash]]></dc:creator>
		<pubDate>Mon, 08 Dec 2008 16:11:40 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=1624#comment-44617</guid>
		<description><![CDATA[Hi all,
Good to see you here and very very thanks for sharing the knowledge.

So anyone can u please tell me about the difference between table variables and the cursors..

which is good one and where??

Thanks
Regards Prakash]]></description>
		<content:encoded><![CDATA[<p>Hi all,<br />
Good to see you here and very very thanks for sharing the knowledge.</p>
<p>So anyone can u please tell me about the difference between table variables and the cursors..</p>
<p>which is good one and where??</p>
<p>Thanks<br />
Regards Prakash</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: pinaldave</title>
		<link>http://blog.sqlauthority.com/2008/12/07/sql-server-interesting-interview-questions/#comment-44612</link>
		<dc:creator><![CDATA[pinaldave]]></dc:creator>
		<pubDate>Mon, 08 Dec 2008 09:32:57 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=1624#comment-44612</guid>
		<description><![CDATA[Dear Readers,

Take this question as T-SQL practice exam rather than schema improvement problem.

In my organization we do not ask this simple question for Schema improvement. Normalization is important but in data warehousing and BI de-normalization is equally important. 

Hope this clear now and waiting for more T-SQL solution to this problem.

Everybody who participated here - Thanks I really see good suggestions.

Kind Regards,
Pinal Dave]]></description>
		<content:encoded><![CDATA[<p>Dear Readers,</p>
<p>Take this question as T-SQL practice exam rather than schema improvement problem.</p>
<p>In my organization we do not ask this simple question for Schema improvement. Normalization is important but in data warehousing and BI de-normalization is equally important. </p>
<p>Hope this clear now and waiting for more T-SQL solution to this problem.</p>
<p>Everybody who participated here &#8211; Thanks I really see good suggestions.</p>
<p>Kind Regards,<br />
Pinal Dave</p>
]]></content:encoded>
	</item>
</channel>
</rss>
