<?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>Notes of a SQL Server MVP and Database Administrator</description>
	<lastBuildDate>Sat, 21 Nov 2009 05:54:09 +0000</lastBuildDate>
	<generator>http://wordpress.com/</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: RakeshA</title>
		<link>http://blog.sqlauthority.com/2008/12/07/sql-server-interesting-interview-questions/#comment-56019</link>
		<dc:creator>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>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(&#8217;stu1&#8242;,1,0,1)<br />
insert into xs values(&#8217;stu2&#8242;,1,0,1)<br />
insert into xs values(&#8217;stu3&#8242;,0,1,0)<br />
insert into xs values(&#8217;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>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>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(&#8217;studentsenroll&#8217;) and name  &#8216;Students&#8217;<br />
Declare c1 cursor<br />
For select Name From sys.columns where object_id = object_id(&#8217;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 +  &#8217;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 +  &#8217;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>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>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>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>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>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>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>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>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>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>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>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>[...] 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>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>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>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>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>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>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(&#8217;students.&#8217; as char(9)) as &#8217;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>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>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>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>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>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>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>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>[...] 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>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>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>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>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>
	<item>
		<title>By: John</title>
		<link>http://blog.sqlauthority.com/2008/12/07/sql-server-interesting-interview-questions/#comment-44610</link>
		<dc:creator>John</dc:creator>
		<pubDate>Mon, 08 Dec 2008 09:06:34 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=1624#comment-44610</guid>
		<description>I&#039;d be concerned about any organisation that asked a question like that.  The table design is terrible, and if it was more normalized, there wouldn&#039;t be any need to come up with clever solutions.

Of course, if the question asked how you would improve the schema and &lt;i&gt;then&lt;/i&gt; return the output that would be acceptable.</description>
		<content:encoded><![CDATA[<p>I&#8217;d be concerned about any organisation that asked a question like that.  The table design is terrible, and if it was more normalized, there wouldn&#8217;t be any need to come up with clever solutions.</p>
<p>Of course, if the question asked how you would improve the schema and <i>then</i> return the output that would be acceptable.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: fly</title>
		<link>http://blog.sqlauthority.com/2008/12/07/sql-server-interesting-interview-questions/#comment-44607</link>
		<dc:creator>fly</dc:creator>
		<pubDate>Mon, 08 Dec 2008 07:48:44 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=1624#comment-44607</guid>
		<description>How about this:

declare @tbl table (i int)
insert into @tbl (i)
select 1
union 
select 2
union 
select 3

select 
	case when i = 1 then &#039;Class 1 has &#039; + cast(sum(cast (class1 as int)) as varchar(100)) + &#039; Students&#039; else 
		case when i = 2 then &#039;Class 2 has &#039; + cast(sum(cast (class2 as int)) as varchar(100)) + &#039; Students&#039; else 
			case when i = 3 then &#039;Class 3 has &#039; + cast(sum(cast (class3 as int)) as varchar(100)) + &#039; Students&#039; else &#039;&#039; end
		end 
	 end
from [StudentsEnroll]
	join @tbl t on i &lt;= 3
group by i</description>
		<content:encoded><![CDATA[<p>How about this:</p>
<p>declare @tbl table (i int)<br />
insert into @tbl (i)<br />
select 1<br />
union<br />
select 2<br />
union<br />
select 3</p>
<p>select<br />
	case when i = 1 then &#8216;Class 1 has &#8216; + cast(sum(cast (class1 as int)) as varchar(100)) + &#8216; Students&#8217; else<br />
		case when i = 2 then &#8216;Class 2 has &#8216; + cast(sum(cast (class2 as int)) as varchar(100)) + &#8216; Students&#8217; else<br />
			case when i = 3 then &#8216;Class 3 has &#8216; + cast(sum(cast (class3 as int)) as varchar(100)) + &#8216; Students&#8217; else &#8221; end<br />
		end<br />
	 end<br />
from [StudentsEnroll]<br />
	join @tbl t on i &lt;= 3<br />
group by i</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: bhadeliaimran</title>
		<link>http://blog.sqlauthority.com/2008/12/07/sql-server-interesting-interview-questions/#comment-44605</link>
		<dc:creator>bhadeliaimran</dc:creator>
		<pubDate>Mon, 08 Dec 2008 06:06:49 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=1624#comment-44605</guid>
		<description>
DECLARE @opXml as XML 

SET @opXml  = &#039;&lt;ClassStud value=&quot;&#039; + REPLACE(
        (SELECT 
            &#039;Class1 has &#039; + CAST(SUM(CAST(Class1 AS SMALLINT)) AS VARCHAR(4)) + &#039; students&#039; , 
            &#039;,Class2 has &#039; + CAST(SUM(CAST(Class2 AS SMALLINT)) AS VARCHAR(4)) + &#039; students&#039; , 
            &#039;,Class3 has &#039; + CAST(SUM(CAST(Class3 AS SMALLINT)) AS VARCHAR(4)) + &#039; students&#039; 
        FROM [StudentsEnroll]
FOR XML PATH(&#039;&#039;) ), &#039;,&#039;, &#039;&quot; /&gt;&lt;ClassStud value=&quot;&#039;) + &#039;&quot; /&gt;&#039;

SELECT     x.value(&#039;@value&#039;, &#039;varchar(100)&#039;) AS [output]    
FROM @opXml.nodes(&#039;/ClassStud&#039;) as p(x)</description>
		<content:encoded><![CDATA[<p>DECLARE @opXml as XML </p>
<p>SET @opXml  = &#8216;&lt;ClassStud value=&#8221;&#8216; + REPLACE(<br />
        (SELECT<br />
            &#8216;Class1 has &#8216; + CAST(SUM(CAST(Class1 AS SMALLINT)) AS VARCHAR(4)) + &#8216; students&#8217; ,<br />
            &#8216;,Class2 has &#8216; + CAST(SUM(CAST(Class2 AS SMALLINT)) AS VARCHAR(4)) + &#8216; students&#8217; ,<br />
            &#8216;,Class3 has &#8216; + CAST(SUM(CAST(Class3 AS SMALLINT)) AS VARCHAR(4)) + &#8216; students&#8217;<br />
        FROM [StudentsEnroll]<br />
FOR XML PATH(&#8221;) ), &#8216;,&#8217;, &#8216;&#8221; /&gt;&lt;ClassStud value=&#8221;&#8216;) + &#8216;&#8221; /&gt;&#8217;</p>
<p>SELECT     x.value(&#8216;@value&#8217;, &#8216;varchar(100)&#8217;) AS [output]<br />
FROM @opXml.nodes(&#8216;/ClassStud&#8217;) as p(x)</p>
]]></content:encoded>
	</item>
</channel>
</rss>
