<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	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:slash="http://purl.org/rss/1.0/modules/slash/"
	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>Melissa Suciadi&#039;s Blog</title>
	<atom:link href="http://melissasuciadi.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://melissasuciadi.wordpress.com</link>
	<description>This is me trying to share what I know.</description>
	<lastBuildDate>Fri, 06 Jan 2012 19:07:43 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='melissasuciadi.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://s2.wp.com/i/buttonw-com.png</url>
		<title>Melissa Suciadi&#039;s Blog</title>
		<link>http://melissasuciadi.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://melissasuciadi.wordpress.com/osd.xml" title="Melissa Suciadi&#039;s Blog" />
	<atom:link rel='hub' href='http://melissasuciadi.wordpress.com/?pushpress=hub'/>
		<item>
		<title>Separate your work and leasure</title>
		<link>http://melissasuciadi.wordpress.com/2012/01/06/separate-your-work-and-pr/</link>
		<comments>http://melissasuciadi.wordpress.com/2012/01/06/separate-your-work-and-pr/#comments</comments>
		<pubDate>Fri, 06 Jan 2012 18:42:55 +0000</pubDate>
		<dc:creator>melissasuciadi</dc:creator>
				<category><![CDATA[Life and all about it]]></category>

		<guid isPermaLink="false">http://melissasuciadi.wordpress.com/2012/01/06/separate-your-work-and-pr/</guid>
		<description><![CDATA[<blockquote>Separate your work and private laptop!!
Leave your work at the right place (OFFICE)</blockquote>
Lifework<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=melissasuciadi.wordpress.com&amp;blog=9216102&amp;post=154&amp;subd=melissasuciadi&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<blockquote><p>Separate your work and private laptop!!<br />
Leave your work at the right place (OFFICE)</p></blockquote>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/melissasuciadi.wordpress.com/154/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/melissasuciadi.wordpress.com/154/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/melissasuciadi.wordpress.com/154/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/melissasuciadi.wordpress.com/154/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/melissasuciadi.wordpress.com/154/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/melissasuciadi.wordpress.com/154/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/melissasuciadi.wordpress.com/154/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/melissasuciadi.wordpress.com/154/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/melissasuciadi.wordpress.com/154/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/melissasuciadi.wordpress.com/154/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/melissasuciadi.wordpress.com/154/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/melissasuciadi.wordpress.com/154/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/melissasuciadi.wordpress.com/154/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/melissasuciadi.wordpress.com/154/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=melissasuciadi.wordpress.com&amp;blog=9216102&amp;post=154&amp;subd=melissasuciadi&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://melissasuciadi.wordpress.com/2012/01/06/separate-your-work-and-pr/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/b60d39bc6491083e945f7818246e7bbd?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">melissasuciadi</media:title>
		</media:content>
	</item>
		<item>
		<title>Life Update 2011</title>
		<link>http://melissasuciadi.wordpress.com/2011/12/26/life-update-2011/</link>
		<comments>http://melissasuciadi.wordpress.com/2011/12/26/life-update-2011/#comments</comments>
		<pubDate>Mon, 26 Dec 2011 10:41:01 +0000</pubDate>
		<dc:creator>melissasuciadi</dc:creator>
				<category><![CDATA[Life and all about it]]></category>
		<category><![CDATA[Life]]></category>

		<guid isPermaLink="false">http://melissasuciadi.wordpress.com/?p=143</guid>
		<description><![CDATA[Since the last I post my last post on March 2010, I&#8217;ve moved to different kind of job, I&#8217;ve moved from Jakarta to Medan and now Surabaya. Life is good.. Before i dedicated this blog to my interest in IT, currently I am not as update as before. So you&#8217;ll see that I am going [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=melissasuciadi.wordpress.com&amp;blog=9216102&amp;post=143&amp;subd=melissasuciadi&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Since the last I post my last post on March 2010, I&#8217;ve moved to different kind of job, I&#8217;ve moved from Jakarta to Medan and now Surabaya.</p>
<p>Life is good..</p>
<p>Before i dedicated this blog to my interest in IT, currently I am not as update as before. So you&#8217;ll see that I am going to write random things.. Such as life, my thought, or anything cross my mind</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/melissasuciadi.wordpress.com/143/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/melissasuciadi.wordpress.com/143/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/melissasuciadi.wordpress.com/143/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/melissasuciadi.wordpress.com/143/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/melissasuciadi.wordpress.com/143/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/melissasuciadi.wordpress.com/143/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/melissasuciadi.wordpress.com/143/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/melissasuciadi.wordpress.com/143/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/melissasuciadi.wordpress.com/143/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/melissasuciadi.wordpress.com/143/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/melissasuciadi.wordpress.com/143/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/melissasuciadi.wordpress.com/143/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/melissasuciadi.wordpress.com/143/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/melissasuciadi.wordpress.com/143/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=melissasuciadi.wordpress.com&amp;blog=9216102&amp;post=143&amp;subd=melissasuciadi&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://melissasuciadi.wordpress.com/2011/12/26/life-update-2011/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/b60d39bc6491083e945f7818246e7bbd?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">melissasuciadi</media:title>
		</media:content>
	</item>
		<item>
		<title>get user who altered stored procedure from server</title>
		<link>http://melissasuciadi.wordpress.com/2010/03/25/get-user-who-altered-stored-procedure-from-server/</link>
		<comments>http://melissasuciadi.wordpress.com/2010/03/25/get-user-who-altered-stored-procedure-from-server/#comments</comments>
		<pubDate>Thu, 25 Mar 2010 12:29:37 +0000</pubDate>
		<dc:creator>melissasuciadi</dc:creator>
				<category><![CDATA[Transact SQL]]></category>
		<category><![CDATA[Alter Procedure]]></category>
		<category><![CDATA[DDL Trigger]]></category>
		<category><![CDATA[History]]></category>
		<category><![CDATA[Last Modify]]></category>
		<category><![CDATA[Log]]></category>
		<category><![CDATA[Logging]]></category>
		<category><![CDATA[trigger]]></category>
		<category><![CDATA[User]]></category>

		<guid isPermaLink="false">http://melissasuciadi.wordpress.com/?p=138</guid>
		<description><![CDATA[First I create a table for logging purpose. CREATE table Logtable (username varchar(2000), Modify_Date datetime, ProcName varchar(2000)) Then I create the Trigger CREATE TRIGGER safety ON DATABASE FOR ALTER_PROCEDURE AS declare @name varchar(200) --look for the object with stored procedure type that has the last modify time. set @name = (select  top 1 Name from [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=melissasuciadi.wordpress.com&amp;blog=9216102&amp;post=138&amp;subd=melissasuciadi&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>First I create a table for logging purpose.</p>
<pre>CREATE table Logtable
(username varchar(2000), Modify_Date datetime, ProcName varchar(2000))</pre>
<p>Then I create the Trigger</p>
<pre>CREATE TRIGGER safety
ON DATABASE
FOR ALTER_PROCEDURE
AS
declare @name varchar(200)

--look for the object with stored procedure type that has the last modify time.
set @name = (select  top 1 Name from sys.all_objects
where type_desc like 'SQL_STORED_PROCEDURE'
order by modify_date desc)

--insert the information u need to log table
INSERT INTO Logtable (UserName, Modify_Date, ProcName)
select suser_name(), getdate(), @name</pre>
<p>create  a dummy proc for testing and alter it for testing the trigger</p>
<pre>create procedure JustAProc
as
select 'JustAProc'
go

ALTER procedure JustAProc
AS BEGIN
PRINT 'X'
END</pre>
<p>see the content of the log</p>
<pre>select * from Logtable
</pre>
<table border="0" cellspacing="0" cellpadding="0" width="286">
<tbody>
<tr>
<td width="64" height="17">username</td>
<td width="129">Modify_Date</td>
<td width="93">ProcName</td>
</tr>
<tr>
<td height="17">Melissa</td>
<td>3/24/10 8:17 PM</td>
<td>JustAProc</td>
</tr>
</tbody>
</table>
<p>and just drop it after you finish play with it</p>
<pre>DROP TRIGGER safety
ON DATABASE;
go
DROP PROCEDURE JustAProc
GO
Drop Table Logtable</pre>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/melissasuciadi.wordpress.com/138/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/melissasuciadi.wordpress.com/138/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/melissasuciadi.wordpress.com/138/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/melissasuciadi.wordpress.com/138/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/melissasuciadi.wordpress.com/138/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/melissasuciadi.wordpress.com/138/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/melissasuciadi.wordpress.com/138/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/melissasuciadi.wordpress.com/138/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/melissasuciadi.wordpress.com/138/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/melissasuciadi.wordpress.com/138/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/melissasuciadi.wordpress.com/138/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/melissasuciadi.wordpress.com/138/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/melissasuciadi.wordpress.com/138/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/melissasuciadi.wordpress.com/138/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=melissasuciadi.wordpress.com&amp;blog=9216102&amp;post=138&amp;subd=melissasuciadi&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://melissasuciadi.wordpress.com/2010/03/25/get-user-who-altered-stored-procedure-from-server/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/b60d39bc6491083e945f7818246e7bbd?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">melissasuciadi</media:title>
		</media:content>
	</item>
		<item>
		<title>The Highest Score in a Class</title>
		<link>http://melissasuciadi.wordpress.com/2010/03/25/the-highest-score-in-a-class/</link>
		<comments>http://melissasuciadi.wordpress.com/2010/03/25/the-highest-score-in-a-class/#comments</comments>
		<pubDate>Thu, 25 Mar 2010 08:14:44 +0000</pubDate>
		<dc:creator>melissasuciadi</dc:creator>
				<category><![CDATA[Transact SQL]]></category>
		<category><![CDATA[CTE]]></category>
		<category><![CDATA[dense_rank()]]></category>
		<category><![CDATA[Max()]]></category>
		<category><![CDATA[row_number()]]></category>
		<category><![CDATA[Top 1]]></category>

		<guid isPermaLink="false">http://melissasuciadi.wordpress.com/?p=134</guid>
		<description><![CDATA[Mrs. Jones is an admin in an elementry school called &#8216;SD Suka Tampil&#8217;. At the end of the school every six months she got to give report to the head master about students with the best score in every class. She has a table. Just a very simple table called StudentScore. The structure is like [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=melissasuciadi.wordpress.com&amp;blog=9216102&amp;post=134&amp;subd=melissasuciadi&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Mrs. Jones is an admin in an elementry school called &#8216;SD Suka Tampil&#8217;. At the end of the school every six months she got to give report to the head master about students with the best score in every class. She has a table. Just a very simple table called StudentScore.</p>
<p>The structure is like</p>
<table border="0" cellspacing="0" cellpadding="0" width="167">
<col width="83"></col>
<col width="40"></col>
<col width="44"></col>
<tbody>
<tr>
<td width="83" height="17"><strong>Name</strong></td>
<td width="40"><strong>Class</strong></td>
<td width="44"><strong>Score</strong></td>
</tr>
<tr>
<td height="17">Mina</td>
<td>1a</td>
<td>99</td>
</tr>
<tr>
<td height="17">Arni</td>
<td>1b</td>
<td>98</td>
</tr>
<tr>
<td height="17">Cukiyem</td>
<td>1a</td>
<td>55</td>
</tr>
<tr>
<td height="17">Alfaredo</td>
<td>1c</td>
<td>78</td>
</tr>
<tr>
<td height="17">Gilda</td>
<td>….</td>
<td></td>
</tr>
</tbody>
</table>
<p>Aa.. just head to the query then to make this shorter.</p>
<pre>CREATE TABLE #StudentScore (Name varchar(20), Class Char(2), Score int)

insert into #StudentScore (Name, Class, Score)
select 'Zee', '1a', 99 UNION ALL
select 'Arni', '1b', 98 UNION ALL
select 'Cukiyem', '1a', 55 UNION ALL
select 'Alfaredo', '1c', 78 UNION ALL
select 'Gilda', '1b', 88 UNION ALL
select 'Moore', '1a', 87 UNION ALL
select 'RiyanT', '1a', 90 UNION ALL
select 'Melissa', '1b', 98 UNION ALL
select 'Ninoood', '1c', 95

select * from #StudentScore</pre>
<table border="0" cellspacing="0" cellpadding="0" width="172">
<tbody>
<tr>
<td width="64" height="17"><strong>Name</strong></td>
<td width="64"><strong>Class</strong></td>
<td width="44"><strong>Score</strong></td>
</tr>
<tr>
<td height="17">Zee</td>
<td>1a</td>
<td align="right">99</td>
</tr>
<tr>
<td height="17">Arni</td>
<td>1b</td>
<td align="right">98</td>
</tr>
<tr>
<td height="17">Cukiyem</td>
<td>1a</td>
<td align="right">55</td>
</tr>
<tr>
<td height="17">Alfaredo</td>
<td>1c</td>
<td align="right">78</td>
</tr>
<tr>
<td height="17">Gilda</td>
<td>1b</td>
<td align="right">88</td>
</tr>
<tr>
<td height="17">Moore</td>
<td>1a</td>
<td align="right">87</td>
</tr>
<tr>
<td height="17">RiyanT</td>
<td>1a</td>
<td align="right">90</td>
</tr>
<tr>
<td height="17">Melissa</td>
<td>1b</td>
<td align="right">98</td>
</tr>
<tr>
<td height="17">Ninoood</td>
<td>1c</td>
<td align="right">95</td>
</tr>
</tbody>
</table>
<p>Ahaha that easy just use max</p>
<pre>select Name, class, MAX(score) as 'The Highest'
from #StudentScore
group by Name, Class</pre>
<table border="0" cellspacing="0" cellpadding="0" width="210">
<col span="2" width="64"></col>
<col width="82"></col>
<tbody>
<tr>
<td width="64" height="17"><strong>Name</strong></td>
<td width="64"><strong>class</strong></td>
<td width="82"><strong>The Highest</strong></td>
</tr>
<tr>
<td height="17">Cukiyem</td>
<td>1a</td>
<td align="right">55</td>
</tr>
<tr>
<td height="17">Moore</td>
<td>1a</td>
<td align="right">87</td>
</tr>
<tr>
<td height="17">RiyanT</td>
<td>1a</td>
<td align="right">90</td>
</tr>
<tr>
<td height="17">Zee</td>
<td>1a</td>
<td align="right">99</td>
</tr>
<tr>
<td height="17">Arni</td>
<td>1b</td>
<td align="right">98</td>
</tr>
<tr>
<td height="17">Gilda</td>
<td>1b</td>
<td align="right">88</td>
</tr>
<tr>
<td height="17">Melissa</td>
<td>1b</td>
<td align="right">98</td>
</tr>
<tr>
<td height="17">Alfaredo</td>
<td>1c</td>
<td align="right">78</td>
</tr>
<tr>
<td height="17">Ninoood</td>
<td>1c</td>
<td align="right">95</td>
</tr>
</tbody>
</table>
<p>Why why why it don&#8217;t produce the right result? hehe cause you group it by the name and class. Hmm&#8230;<br />
Let&#8217;s Find the highest first in every Class</p>
<pre>select Class,  MAX(score) AS Score
from #StudentScore
group by Class</pre>
<table border="0" cellspacing="0" cellpadding="0" width="81">
<col width="40"></col>
<col width="41"></col>
<tbody>
<tr>
<td width="40" height="17"><strong>Class</strong></td>
<td width="41"><strong>Score</strong></td>
</tr>
<tr>
<td height="17">1a</td>
<td align="right">99</td>
</tr>
<tr>
<td height="17">1b</td>
<td align="right">98</td>
</tr>
<tr>
<td height="17">1c</td>
<td align="right">95</td>
</tr>
</tbody>
</table>
<p>Ahaaaa&#8230;.</p>
<pre>SELECT A.name, A.Class, A.Score as 'The Highest'
from #StudentScore A
JOIN (select Class,  MAX(score) AS Score
 from #StudentScore
 group by Class
 ) B ON A.Class = B.Class AND A.Score = B.Score</pre>
<table border="0" cellspacing="0" cellpadding="0" width="180">
<col width="58"></col>
<col width="40"></col>
<col width="82"></col>
<tbody>
<tr>
<td width="58" height="17"><strong>name</strong></td>
<td width="40"><strong>Class</strong></td>
<td width="82"><strong>The Highest</strong></td>
</tr>
<tr>
<td height="17">Ninoood</td>
<td>1c</td>
<td align="right">95</td>
</tr>
<tr>
<td height="17">Arni</td>
<td>1b</td>
<td align="right">98</td>
</tr>
<tr>
<td height="17">Melissa</td>
<td>1b</td>
<td align="right">98</td>
</tr>
<tr>
<td height="17">Zee</td>
<td>1a</td>
<td align="right">99</td>
</tr>
</tbody>
</table>
<p>Or use CTE</p>
<pre>;WITH CTE AS (
SELECT Name, Class, Score,
ROW_NUMBER() OVER (PARTITION BY Class Order by Score DESC) AS RN
FROM #StudentScore
)SELECT Name, Class, Score FROM CTE
 WHERE RN = 1;</pre>
<table border="0" cellspacing="0" cellpadding="0" width="180">
<col width="58"></col>
<col width="40"></col>
<col width="82"></col>
<tbody>
<tr>
<td width="58" height="17">Name</td>
<td width="40">Class</td>
<td width="82">Score</td>
</tr>
<tr>
<td height="17">Zee</td>
<td>1a</td>
<td align="right">99</td>
</tr>
<tr>
<td height="17">Arni</td>
<td>1b</td>
<td align="right">98</td>
</tr>
<tr>
<td height="17">Ninoood</td>
<td>1c</td>
<td align="right">95</td>
</tr>
</tbody>
</table>
<p>wait why we can see melissa in class 1b?  please see below</p>
<pre>SELECT Name, Class, Score,
ROW_NUMBER() OVER (PARTITION BY Class Order by Score DESC) AS RN
FROM #StudentScore</pre>
<table border="0" cellspacing="0" cellpadding="0" width="199">
<col width="64"></col>
<col width="54"></col>
<col width="41"></col>
<col width="40"></col>
<tbody>
<tr>
<td width="64" height="17">Name</td>
<td width="54">Class</td>
<td width="41">Score</td>
<td width="40">RN</td>
</tr>
<tr>
<td height="17">Zee</td>
<td>1a</td>
<td align="right">99</td>
<td align="right">1</td>
</tr>
<tr>
<td height="17">RiyanT</td>
<td>1a</td>
<td align="right">90</td>
<td align="right">2</td>
</tr>
<tr>
<td height="17">Moore</td>
<td>1a</td>
<td align="right">87</td>
<td align="right">3</td>
</tr>
<tr>
<td height="17">Cukiyem</td>
<td>1a</td>
<td align="right">55</td>
<td align="right">4</td>
</tr>
<tr>
<td height="17">Arni</td>
<td>1b</td>
<td align="right">98</td>
<td align="right">1</td>
</tr>
<tr>
<td height="17"><strong>Melissa</strong></td>
<td><strong>1b</strong></td>
<td align="right"><strong>98</strong></td>
<td align="right"><strong>2</strong></td>
</tr>
<tr>
<td height="17">Gilda</td>
<td>1b</td>
<td align="right">88</td>
<td align="right">3</td>
</tr>
<tr>
<td height="17">Ninoood</td>
<td>1c</td>
<td align="right">95</td>
<td align="right">1</td>
</tr>
<tr>
<td height="17">Alfaredo</td>
<td>1c</td>
<td align="right">78</td>
<td align="right">2</td>
</tr>
</tbody>
</table>
<p>why melissa is grade as number 2 in class 1b? because row number sort the score based on score<br />
and when they found two same score it&#8217;ll sort again by name. And A comes first.<br />
so how to have this with CTE. Use Dense Rank!</p>
<pre>SELECT Name, Class, Score,
Dense_rank() OVER (PARTITION BY Class Order by Score DESC) AS RN
FROM #StudentScore</pre>
<table border="0" cellspacing="0" cellpadding="0" width="199">
<col width="64"></col>
<col width="54"></col>
<col width="41"></col>
<col width="40"></col>
<tbody>
<tr>
<td width="64" height="17"><strong>Name</strong></td>
<td width="54"><strong>Class</strong></td>
<td width="41"><strong>Score</strong></td>
<td width="40"><strong>RN</strong></td>
</tr>
<tr>
<td height="17">Zee</td>
<td>1a</td>
<td align="right">99</td>
<td align="right">1</td>
</tr>
<tr>
<td height="17">RiyanT</td>
<td>1a</td>
<td align="right">90</td>
<td align="right">2</td>
</tr>
<tr>
<td height="17">Moore</td>
<td>1a</td>
<td align="right">87</td>
<td align="right">3</td>
</tr>
<tr>
<td height="17">Cukiyem</td>
<td>1a</td>
<td align="right">55</td>
<td align="right">4</td>
</tr>
<tr>
<td height="17"><strong>Arni</strong></td>
<td><strong>1b</strong></td>
<td align="right"><strong>98</strong></td>
<td align="right"><strong>1</strong></td>
</tr>
<tr>
<td height="17"><strong>Melissa</strong></td>
<td><strong>1b</strong></td>
<td align="right"><strong>98</strong></td>
<td align="right"><strong>1</strong></td>
</tr>
<tr>
<td height="17">Gilda</td>
<td>1b</td>
<td align="right">88</td>
<td align="right">2</td>
</tr>
<tr>
<td height="17">Ninoood</td>
<td>1c</td>
<td align="right">95</td>
<td align="right">1</td>
</tr>
<tr>
<td height="17">Alfaredo</td>
<td>1c</td>
<td align="right">78</td>
<td align="right">2</td>
</tr>
</tbody>
</table>
<p>Now we have Melissa and Arni in the same position<br />
tadaaaa.</p>
<pre>;WITH CTE AS (
SELECT Name, Class, Score,
Dense_rank() OVER (PARTITION BY Class Order by Score DESC) AS RN
FROM #StudentScore
)SELECT Name, Class, Score FROM CTE
 WHERE RN = 1;</pre>
<p>I present to You&#8230;</p>
<p>Report For Miss Jones..</p>
<table border="0" cellspacing="0" cellpadding="0" width="159">
<col width="64"></col>
<col width="54"></col>
<col width="41"></col>
<tbody>
<tr>
<td width="64" height="17"><strong>Name</strong></td>
<td width="54"><strong>Class</strong></td>
<td width="41"><strong>Score</strong></td>
</tr>
<tr>
<td height="17">Zee</td>
<td>1a</td>
<td align="right">99</td>
</tr>
<tr>
<td height="17">Arni</td>
<td>1b</td>
<td align="right">98</td>
</tr>
<tr>
<td height="17">Melissa</td>
<td>1b</td>
<td align="right">98</td>
</tr>
<tr>
<td height="17">Ninoood</td>
<td>1c</td>
<td align="right">95</td>
</tr>
</tbody>
</table>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/melissasuciadi.wordpress.com/134/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/melissasuciadi.wordpress.com/134/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/melissasuciadi.wordpress.com/134/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/melissasuciadi.wordpress.com/134/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/melissasuciadi.wordpress.com/134/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/melissasuciadi.wordpress.com/134/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/melissasuciadi.wordpress.com/134/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/melissasuciadi.wordpress.com/134/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/melissasuciadi.wordpress.com/134/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/melissasuciadi.wordpress.com/134/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/melissasuciadi.wordpress.com/134/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/melissasuciadi.wordpress.com/134/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/melissasuciadi.wordpress.com/134/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/melissasuciadi.wordpress.com/134/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=melissasuciadi.wordpress.com&amp;blog=9216102&amp;post=134&amp;subd=melissasuciadi&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://melissasuciadi.wordpress.com/2010/03/25/the-highest-score-in-a-class/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/b60d39bc6491083e945f7818246e7bbd?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">melissasuciadi</media:title>
		</media:content>
	</item>
		<item>
		<title>Insert to another table after inserting to a table</title>
		<link>http://melissasuciadi.wordpress.com/2010/03/24/insert-to-another-table-after-inserting-to-a-table/</link>
		<comments>http://melissasuciadi.wordpress.com/2010/03/24/insert-to-another-table-after-inserting-to-a-table/#comments</comments>
		<pubDate>Wed, 24 Mar 2010 15:26:55 +0000</pubDate>
		<dc:creator>melissasuciadi</dc:creator>
				<category><![CDATA[Transact SQL]]></category>
		<category><![CDATA[@@identity]]></category>
		<category><![CDATA[after insert]]></category>
		<category><![CDATA[Create Trigger]]></category>

		<guid isPermaLink="false">http://melissasuciadi.wordpress.com/?p=132</guid>
		<description><![CDATA[This is quite an often question asked by people. There are 2 options. Create a stored procedure with 2 steps something like This is quite an often question asked by people. There are 2 options. Create a stored procedure with 2 steps something like. It&#8217;ll insert the last value inserted to table A to table B [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=melissasuciadi.wordpress.com&amp;blog=9216102&amp;post=132&amp;subd=melissasuciadi&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<div id="_mcePaste">This is quite an often question asked by people.</div>
<div id="_mcePaste">There are 2 options. Create a stored procedure with 2 steps</div>
<div id="_mcePaste">something like</div>
<p>This is quite an often question asked by people.<br />
There are 2 options. Create a stored procedure with 2 steps something like. It&#8217;ll insert the last value inserted to table A to table B</p>
<pre>CREATE PROCEDURE InsertInsert

AS BEGIN

declare @id int
Insert to table A
select 'A', 'B'

--take the last id inserted
SET @id = @@identity

GO

Insert to table B
Select Col1, Col2 from Table A
where ID = @id

END</pre>
<p>or you can use trigger.</p>
<pre>CREATE TRIGGER InsertToOtherTable
ON TableSource
AFTER INSERT
AS
INSERT INTO TableB
SELECT Col1, Col2
FROM INSERTED</pre>
<p><a href="http://msdn.microsoft.com/en-us/library/ms189799.aspx">BOL</a></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/melissasuciadi.wordpress.com/132/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/melissasuciadi.wordpress.com/132/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/melissasuciadi.wordpress.com/132/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/melissasuciadi.wordpress.com/132/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/melissasuciadi.wordpress.com/132/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/melissasuciadi.wordpress.com/132/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/melissasuciadi.wordpress.com/132/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/melissasuciadi.wordpress.com/132/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/melissasuciadi.wordpress.com/132/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/melissasuciadi.wordpress.com/132/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/melissasuciadi.wordpress.com/132/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/melissasuciadi.wordpress.com/132/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/melissasuciadi.wordpress.com/132/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/melissasuciadi.wordpress.com/132/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=melissasuciadi.wordpress.com&amp;blog=9216102&amp;post=132&amp;subd=melissasuciadi&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://melissasuciadi.wordpress.com/2010/03/24/insert-to-another-table-after-inserting-to-a-table/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/b60d39bc6491083e945f7818246e7bbd?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">melissasuciadi</media:title>
		</media:content>
	</item>
		<item>
		<title>Query to know the Object Level Permissions for all users of a Database</title>
		<link>http://melissasuciadi.wordpress.com/2010/03/24/query-to-know-the-object-level-permissions-for-all-users-of-a-database/</link>
		<comments>http://melissasuciadi.wordpress.com/2010/03/24/query-to-know-the-object-level-permissions-for-all-users-of-a-database/#comments</comments>
		<pubDate>Wed, 24 Mar 2010 09:22:24 +0000</pubDate>
		<dc:creator>melissasuciadi</dc:creator>
				<category><![CDATA[Transact SQL]]></category>
		<category><![CDATA[object]]></category>
		<category><![CDATA[sys. level permission]]></category>

		<guid isPermaLink="false">http://melissasuciadi.wordpress.com/?p=124</guid>
		<description><![CDATA[sometimes we need to know what user is allowed to do what then here&#8217;s the query to know the level permission of all user. select pr.name as LoginName, state_desc,  permission_name as PermissionTo , s.name as schemaName, o.Name from sys.database_permissions p inner join  sys.objects o on  p.major_id =o.object_id inner join sys.schemas s on o.schema_id=s.schema_id inner join [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=melissasuciadi.wordpress.com&amp;blog=9216102&amp;post=124&amp;subd=melissasuciadi&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>sometimes we need to know what user is allowed to do what then here&#8217;s the query to know the level permission of all user.</p>
<pre>select pr.name as LoginName, state_desc,  permission_name as PermissionTo , s.name as schemaName, o.Name
from sys.database_permissions p
inner join  sys.objects o on  p.major_id =o.object_id
inner join sys.schemas s on o.schema_id=s.schema_id
inner join sys.database_principals pr on grantee_principal_id=pr.principal_id
</pre>
<p>LoginName  state_desc      	PermissionTo 	schemaName          	Name<br />
User1           	 	GRANT	          	EXECUTE           		dbo                      	USP_A<br />
User2              GRANT           		EXECUTE            		dbo                     	USP_B</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/melissasuciadi.wordpress.com/124/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/melissasuciadi.wordpress.com/124/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/melissasuciadi.wordpress.com/124/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/melissasuciadi.wordpress.com/124/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/melissasuciadi.wordpress.com/124/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/melissasuciadi.wordpress.com/124/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/melissasuciadi.wordpress.com/124/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/melissasuciadi.wordpress.com/124/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/melissasuciadi.wordpress.com/124/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/melissasuciadi.wordpress.com/124/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/melissasuciadi.wordpress.com/124/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/melissasuciadi.wordpress.com/124/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/melissasuciadi.wordpress.com/124/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/melissasuciadi.wordpress.com/124/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=melissasuciadi.wordpress.com&amp;blog=9216102&amp;post=124&amp;subd=melissasuciadi&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://melissasuciadi.wordpress.com/2010/03/24/query-to-know-the-object-level-permissions-for-all-users-of-a-database/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/b60d39bc6491083e945f7818246e7bbd?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">melissasuciadi</media:title>
		</media:content>
	</item>
		<item>
		<title>Insert into Identity Column</title>
		<link>http://melissasuciadi.wordpress.com/2010/01/22/insert-into-identity-column/</link>
		<comments>http://melissasuciadi.wordpress.com/2010/01/22/insert-into-identity-column/#comments</comments>
		<pubDate>Fri, 22 Jan 2010 02:59:03 +0000</pubDate>
		<dc:creator>melissasuciadi</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[identity column]]></category>
		<category><![CDATA[insert into identity column]]></category>
		<category><![CDATA[SET IDENTITY_INSERT to ON]]></category>

		<guid isPermaLink="false">http://melissasuciadi.wordpress.com/?p=117</guid>
		<description><![CDATA[You create a table with identity column, You accidentally delete one of its row instead update it.. If you insert new column it&#8217;ll only increment to the last id inserted+1. You need it to be a specific id. So you try to insert it with the id specified but you cannot do that you get [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=melissasuciadi.wordpress.com&amp;blog=9216102&amp;post=117&amp;subd=melissasuciadi&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>You create a table with identity column, You accidentally delete one of its row instead update it.. If you insert new column it&#8217;ll only increment to the last id inserted+1. You need it to be a specific id. So you try to insert it with the id specified but you cannot do that you get error.. So how to insert column to identity column?</p>
<pre>CREATE TABLE #Customer(
ID INT IDENTITY NOT NULL PRIMARY KEY,
Name VARCHAR(40) NOT NULL
)
GO
-- Inserting values into #Customer table.
INSERT INTO #Customer(Name) VALUES ('Jake')
INSERT INTO #Customer(Name) VALUES ('Suzan')
INSERT INTO #Customer(Name) VALUES ('Marry')
INSERT INTO #Customer(Name) VALUES ('Sally')
GO

-- Accidentaly delete Marry (oh nooo I just want to add Marry's Maiden name!?!?!)
DELETE #Customer
WHERE Name = 'Marry'
GO

SELECT *
FROM #Customer
GO

-- Try to insert Marry again to ID 3;
-- got an error.
INSERT INTO #Customer (ID, Name) VALUES (3, 'Marry Marc')
GO
-- SET IDENTITY_INSERT to ON.
SET IDENTITY_INSERT #Customer ON
GO

-- Try to insert an explicit ID value of 3.
INSERT INTO #Customer (ID, Name) VALUES (3, 'Marry Marc')
GO

SELECT *
FROM #Customer
GO

--Don't forget to set the identity insert back off. <img src='http://s0.wp.com/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' />
SET IDENTITY_INSERT #Customer OFF
GO

-- Drop Customer table.
DROP TABLE #Customer
GO
</pre>
<p>Huraaah!!</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/melissasuciadi.wordpress.com/117/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/melissasuciadi.wordpress.com/117/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/melissasuciadi.wordpress.com/117/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/melissasuciadi.wordpress.com/117/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/melissasuciadi.wordpress.com/117/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/melissasuciadi.wordpress.com/117/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/melissasuciadi.wordpress.com/117/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/melissasuciadi.wordpress.com/117/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/melissasuciadi.wordpress.com/117/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/melissasuciadi.wordpress.com/117/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/melissasuciadi.wordpress.com/117/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/melissasuciadi.wordpress.com/117/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/melissasuciadi.wordpress.com/117/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/melissasuciadi.wordpress.com/117/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=melissasuciadi.wordpress.com&amp;blog=9216102&amp;post=117&amp;subd=melissasuciadi&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://melissasuciadi.wordpress.com/2010/01/22/insert-into-identity-column/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/b60d39bc6491083e945f7818246e7bbd?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">melissasuciadi</media:title>
		</media:content>
	</item>
		<item>
		<title>How to convert time format to minutes/duration</title>
		<link>http://melissasuciadi.wordpress.com/2010/01/22/how-to-convert-time-format-to-minutesduration/</link>
		<comments>http://melissasuciadi.wordpress.com/2010/01/22/how-to-convert-time-format-to-minutesduration/#comments</comments>
		<pubDate>Fri, 22 Jan 2010 02:01:26 +0000</pubDate>
		<dc:creator>melissasuciadi</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[convert time to duration]]></category>
		<category><![CDATA[datediff]]></category>
		<category><![CDATA[datepart]]></category>
		<category><![CDATA[datetime to minutes]]></category>

		<guid isPermaLink="false">http://melissasuciadi.wordpress.com/?p=114</guid>
		<description><![CDATA[Have you ever face trouble when you need to convert values like &#8217;00:45:00.00&#8242; to 45 minutes or &#8217;01:23:00.000&#8242; to 83 minutes? How do you do it? here&#8217;s the input : declare @time datetime set @time = '01:45:00.000' This is the first method, the idea is using datepart function to get the hour part and minute [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=melissasuciadi.wordpress.com&amp;blog=9216102&amp;post=114&amp;subd=melissasuciadi&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Have you ever face trouble when you need to convert values like &#8217;00:45:00.00&#8242; to 45 minutes or &#8217;01:23:00.000&#8242; to 83 minutes?</p>
<p>How do you do it?</p>
<p>here&#8217;s the input :</p>
<pre>declare @time datetime
set @time = '01:45:00.000'
</pre>
<p>This is the first method, the idea is using datepart function to get the hour part and minute part of the data and multiply the hour by 60 then add it with the minute part.</p>
<pre>select datepart(hour,@time) AS hour, datepart(MINUTE,@time) AS min,
datepart(hour,@time)*60 +datepart(MINUTE,@time) As Duration
</pre>
<p>the 2nd method, I like this one better cause it&#8217;s simpler. The idea is looking the difference in minutes from 00:00:00.000 represented by 0 to the data..</p>
<pre>Select DATEDIFF(minute, 0, @time) As Duration
</pre>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/melissasuciadi.wordpress.com/114/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/melissasuciadi.wordpress.com/114/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/melissasuciadi.wordpress.com/114/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/melissasuciadi.wordpress.com/114/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/melissasuciadi.wordpress.com/114/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/melissasuciadi.wordpress.com/114/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/melissasuciadi.wordpress.com/114/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/melissasuciadi.wordpress.com/114/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/melissasuciadi.wordpress.com/114/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/melissasuciadi.wordpress.com/114/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/melissasuciadi.wordpress.com/114/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/melissasuciadi.wordpress.com/114/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/melissasuciadi.wordpress.com/114/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/melissasuciadi.wordpress.com/114/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=melissasuciadi.wordpress.com&amp;blog=9216102&amp;post=114&amp;subd=melissasuciadi&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://melissasuciadi.wordpress.com/2010/01/22/how-to-convert-time-format-to-minutesduration/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/b60d39bc6491083e945f7818246e7bbd?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">melissasuciadi</media:title>
		</media:content>
	</item>
		<item>
		<title>error :Msg 8133, Level 16, State 1, Line 7 ; None of the result expressions in a CASE specification can be NULL.</title>
		<link>http://melissasuciadi.wordpress.com/2010/01/15/error-msg-8133-level-16-state-1-line-7-none-of-the-result-expressions-in-a-case-specification-can-be-null/</link>
		<comments>http://melissasuciadi.wordpress.com/2010/01/15/error-msg-8133-level-16-state-1-line-7-none-of-the-result-expressions-in-a-case-specification-can-be-null/#comments</comments>
		<pubDate>Fri, 15 Jan 2010 01:30:31 +0000</pubDate>
		<dc:creator>melissasuciadi</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Case]]></category>
		<category><![CDATA[SQL Server]]></category>

		<guid isPermaLink="false">http://melissasuciadi.wordpress.com/?p=103</guid>
		<description><![CDATA[above error is happen because the SQl is confuse what is the datatype for the result expression in the case statement.. here&#8217;s simple script to produce the same error and the solutiooooon (at least it worked for me ) declare @i int set @i = 3 declare @x int set @x = 6 Select case [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=melissasuciadi.wordpress.com&amp;blog=9216102&amp;post=103&amp;subd=melissasuciadi&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>above error is happen because the SQl is confuse what is the datatype for the result expression in the case statement..</p>
<p>here&#8217;s simple script to produce the same error and the solutiooooon (at least it worked for me <img src='http://s0.wp.com/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' /> )</p>
<pre>declare @i int
set @i = 3

declare @x int
set @x = 6

Select case when @i &gt;8  OR @i &lt;@x
then NULL
END AS 'Derived Column'
----error :Msg 8133, Level 16, State 1, Line 7
----None of the result expressions in a CASE specification can be NULL.</pre>
<p><strong>ALTERNATIVE :</strong></p>
<pre>Select case when @i &gt;8  OR @i &lt;@x
then 'Something' --different value
END AS 'Derived Column'</pre>
<p>Why It Worked  : because you assign one of the value to varchar so sql thought ok the null is varchar, follow the other value)<br />
second alternative :</p>
<pre>Select case when @i &gt;8  OR @i &lt;@x
then NULL
Else 'X' -- put dummy thingy
END AS 'Derived Column'</pre>
<p>Why it worked : It Worked because you don&#8217;t even try to assign it to NULL value</p>
<p>But but I need to assign it to NULL and no other value and I don&#8217;t want and else..</p>
<p><strong>AHAAA&#8230;</strong></p>
<pre>Select case when @i &gt;8  OR @i &lt;@x
then cast(NULL as int)
END AS 'Derived Column'</pre>
<p>why why ? here you cast the result to a datatype (here i cast it to int, sql is no longer confuse)..</p>
<p>No nooo.. I want assign it to a varchar then so be it.. <img src='http://s0.wp.com/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' /> </p>
<pre>Select case when @i &gt;8  OR @i &lt;@x
 then convert(varchar(10),NULL)
 END AS 'Derived Column'</pre>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/melissasuciadi.wordpress.com/103/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/melissasuciadi.wordpress.com/103/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/melissasuciadi.wordpress.com/103/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/melissasuciadi.wordpress.com/103/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/melissasuciadi.wordpress.com/103/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/melissasuciadi.wordpress.com/103/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/melissasuciadi.wordpress.com/103/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/melissasuciadi.wordpress.com/103/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/melissasuciadi.wordpress.com/103/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/melissasuciadi.wordpress.com/103/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/melissasuciadi.wordpress.com/103/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/melissasuciadi.wordpress.com/103/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/melissasuciadi.wordpress.com/103/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/melissasuciadi.wordpress.com/103/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=melissasuciadi.wordpress.com&amp;blog=9216102&amp;post=103&amp;subd=melissasuciadi&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://melissasuciadi.wordpress.com/2010/01/15/error-msg-8133-level-16-state-1-line-7-none-of-the-result-expressions-in-a-case-specification-can-be-null/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/b60d39bc6491083e945f7818246e7bbd?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">melissasuciadi</media:title>
		</media:content>
	</item>
		<item>
		<title>DateTime to Varchar to Varbinary to Varchar to DateTime</title>
		<link>http://melissasuciadi.wordpress.com/2010/01/14/datetime-to-varchar-to-varbinary-to-varchar-to-datetime/</link>
		<comments>http://melissasuciadi.wordpress.com/2010/01/14/datetime-to-varchar-to-varbinary-to-varchar-to-datetime/#comments</comments>
		<pubDate>Thu, 14 Jan 2010 10:25:33 +0000</pubDate>
		<dc:creator>melissasuciadi</dc:creator>
				<category><![CDATA[Transact SQL]]></category>
		<category><![CDATA[Convert varbinary to date]]></category>
		<category><![CDATA[convert varbinary to varchar]]></category>
		<category><![CDATA[convert varchar to varbinary]]></category>

		<guid isPermaLink="false">http://melissasuciadi.wordpress.com/?p=98</guid>
		<description><![CDATA[My first post on 2010.. Yay!! The First is convert between datatypes. The Idea is convert from datetime to varchar to binary to varchar again to datetime .. DECLARE @DateWithDateTime DATETIME SET @DateWithDateTime = '2010-09-08 00:00:00:00' DECLARE @Date varchar(200) SET @Date = (SELECT CONVERT(VARCHAR(20), @DateWithDateTime, 120)) SELECT CONVERT(VARBINARY(100), @Date)AS theVarbinary --theVarbinary --0x323031302D30392D30382030303A30303A30303A3030 SELECT convert(VARCHAR(200),CONVERT(VARBINARY(100), @Date)) [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=melissasuciadi.wordpress.com&amp;blog=9216102&amp;post=98&amp;subd=melissasuciadi&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>My first post on 2010.. Yay!! The First is convert between datatypes. The Idea is convert from datetime to varchar to binary to varchar again to datetime .. <img src='http://s0.wp.com/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' /> </p>
<pre>
DECLARE @DateWithDateTime DATETIME
SET @DateWithDateTime = '2010-09-08 00:00:00:00'

DECLARE @Date varchar(200)
SET @Date = (SELECT CONVERT(VARCHAR(20), @DateWithDateTime, 120))

SELECT CONVERT(VARBINARY(100), @Date)AS theVarbinary
--theVarbinary
--0x323031302D30392D30382030303A30303A30303A3030

SELECT convert(VARCHAR(200),CONVERT(VARBINARY(100), @Date)) AS BackTodate
--BackTodate
--2010-09-08 00:00:00:00</pre>
<p>hey where is back to datetime.. hahaha it&#8217;s just to complete the cycle(feels good)..</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/melissasuciadi.wordpress.com/98/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/melissasuciadi.wordpress.com/98/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/melissasuciadi.wordpress.com/98/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/melissasuciadi.wordpress.com/98/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/melissasuciadi.wordpress.com/98/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/melissasuciadi.wordpress.com/98/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/melissasuciadi.wordpress.com/98/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/melissasuciadi.wordpress.com/98/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/melissasuciadi.wordpress.com/98/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/melissasuciadi.wordpress.com/98/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/melissasuciadi.wordpress.com/98/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/melissasuciadi.wordpress.com/98/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/melissasuciadi.wordpress.com/98/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/melissasuciadi.wordpress.com/98/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=melissasuciadi.wordpress.com&amp;blog=9216102&amp;post=98&amp;subd=melissasuciadi&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://melissasuciadi.wordpress.com/2010/01/14/datetime-to-varchar-to-varbinary-to-varchar-to-datetime/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/b60d39bc6491083e945f7818246e7bbd?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">melissasuciadi</media:title>
		</media:content>
	</item>
	</channel>
</rss>
