<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blog.4penny.net/utility/FeedStylesheets/atom.xsl" media="screen"?><feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en"><title type="html">SQL Server (T-SQL)</title><subtitle type="html">Comments and notes on SQL Server 2000, 2005, and T-SQL</subtitle><id>http://blog.4penny.net/blogs/sqlserver/atom.aspx</id><link rel="alternate" type="text/html" href="http://blog.4penny.net/blogs/sqlserver/default.aspx" /><link rel="self" type="application/atom+xml" href="http://blog.4penny.net/blogs/sqlserver/atom.aspx" /><generator uri="http://communityserver.org" version="3.0.20611.960">Community Server</generator><updated>2008-05-15T08:10:00Z</updated><entry><title>Cursor Template</title><link rel="alternate" type="text/html" href="http://blog.4penny.net/blogs/sqlserver/archive/2008/07/01/cursor-template.aspx" /><id>http://blog.4penny.net/blogs/sqlserver/archive/2008/07/01/cursor-template.aspx</id><published>2008-07-01T13:22:00Z</published><updated>2008-07-01T13:22:00Z</updated><content type="html">&lt;p&gt;This is the cursor template that I use... it works better than the default one, and allows BREAK and CONTINUE easily&lt;/p&gt;
&lt;p&gt;&lt;pre style="overflow: scroll; background-color: #f2f2f2;"&gt;&lt;span style="color: Black;background-color: Transparent;font-family: Courier New;font-size: 11px;font-weight: normal;"&gt; &lt;span style="color: Blue;background-color: Transparent;font-family: Courier New;font-size: 11px;font-weight: normal;"&gt;DECLARE&lt;/span&gt; curName &lt;span style="color: Blue;background-color: Transparent;font-family: Courier New;font-size: 11px;font-weight: normal;"&gt;CURSOR&lt;/span&gt; KEYSET &lt;span style="color: Blue;background-color: Transparent;font-family: Courier New;font-size: 11px;font-weight: normal;"&gt;FOR&lt;/span&gt; 
 &lt;span style="color: Blue;background-color: Transparent;font-family: Courier New;font-size: 11px;font-weight: normal;"&gt;select&lt;/span&gt; *
  &lt;span style="color: Blue;background-color: Transparent;font-family: Courier New;font-size: 11px;font-weight: normal;"&gt;from&lt;/span&gt; mytablename
&lt;span style="color: Blue;background-color: Transparent;font-family: Courier New;font-size: 11px;font-weight: normal;"&gt;DECLARE&lt;/span&gt; variables
&lt;span style="color: Blue;background-color: Transparent;font-family: Courier New;font-size: 11px;font-weight: normal;"&gt;OPEN&lt;/span&gt; curName
&lt;span style="color: Blue;background-color: Transparent;font-family: Courier New;font-size: 11px;font-weight: normal;"&gt;WHILE&lt;/span&gt; 1=1 
&lt;span style="color: Blue;background-color: Transparent;font-family: Courier New;font-size: 11px;font-weight: normal;"&gt;BEGIN&lt;/span&gt;
 &lt;span style="color: Blue;background-color: Transparent;font-family: Courier New;font-size: 11px;font-weight: normal;"&gt;FETCH&lt;/span&gt; NEXT &lt;span style="color: Blue;background-color: Transparent;font-family: Courier New;font-size: 11px;font-weight: normal;"&gt;FROM&lt;/span&gt; curSopUpdate23 &lt;span style="color: Blue;background-color: Transparent;font-family: Courier New;font-size: 11px;font-weight: normal;"&gt;INTO&lt;/span&gt; @sopnumbe,@soptype,@dtOnTruck, @dtOnJob
 &lt;span style="color: Blue;background-color: Transparent;font-family: Courier New;font-size: 11px;font-weight: normal;"&gt;if&lt;/span&gt; &lt;span style="color: Fuchsia;background-color: Transparent;font-family: Courier New;font-size: 11px;font-weight: normal;"&gt;@@fetch_status&lt;/span&gt; &amp;lt;&amp;gt; 0 &lt;span style="color: Blue;background-color: Transparent;font-family: Courier New;font-size: 11px;font-weight: normal;"&gt;begin&lt;/span&gt;
  &lt;span style="color: Blue;background-color: Transparent;font-family: Courier New;font-size: 11px;font-weight: normal;"&gt;break&lt;/span&gt;
 &lt;span style="color: Blue;background-color: Transparent;font-family: Courier New;font-size: 11px;font-weight: normal;"&gt;end&lt;/span&gt; 


&lt;span style="color: Blue;background-color: Transparent;font-family: Courier New;font-size: 11px;font-weight: normal;"&gt;END&lt;/span&gt;
&lt;span style="color: Blue;background-color: Transparent;font-family: Courier New;font-size: 11px;font-weight: normal;"&gt;CLOSE&lt;/span&gt; curName
&lt;span style="color: Blue;background-color: Transparent;font-family: Courier New;font-size: 11px;font-weight: normal;"&gt;DEALLOCATE&lt;/span&gt; curName&lt;/span&gt;&lt;/pre&gt;&lt;/p&gt;&lt;img src="http://blog.4penny.net/aggbug.aspx?PostID=1115" width="1" height="1"&gt;</content><author><name>Steve Gray</name><uri>http://blog.4penny.net/members/Steve-Gray.aspx</uri></author></entry><entry><title>Grant permissions cursor</title><link rel="alternate" type="text/html" href="http://blog.4penny.net/blogs/sqlserver/archive/2008/06/13/grant-permissions-cursor.aspx" /><id>http://blog.4penny.net/blogs/sqlserver/archive/2008/06/13/grant-permissions-cursor.aspx</id><published>2008-06-13T12:43:00Z</published><updated>2008-06-13T12:43:00Z</updated><content type="html">&lt;p&gt;DECLARE @name varchar(255),&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; @sql varchar(255)&lt;/p&gt;
&lt;p&gt;DECLARE curName CURSOR KEYSET FOR &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; select name&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; from sys.objects&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; where type = &amp;#39;p&amp;#39;&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;OPEN curName&lt;/p&gt;
&lt;p&gt;WHILE 1=1 &lt;br /&gt;BEGIN&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; FETCH NEXT FROM curName INTO @name&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if @@fetch_status &amp;lt;&amp;gt; 0 begin&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; break&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; end &lt;/p&gt;
&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; SET @sql = &amp;#39;grant exec on &amp;#39; + @name + &amp;#39; to chemsys&amp;#39;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; exec (@sql)&lt;br /&gt;END&lt;/p&gt;
&lt;p&gt;CLOSE curName&lt;br /&gt;DEALLOCATE curName&lt;br /&gt;GO&lt;/p&gt;&lt;img src="http://blog.4penny.net/aggbug.aspx?PostID=1064" width="1" height="1"&gt;</content><author><name>Crystal</name><uri>http://blog.4penny.net/members/Crystal.aspx</uri></author></entry><entry><title>Returning the current time in SQL Server</title><link rel="alternate" type="text/html" href="http://blog.4penny.net/blogs/sqlserver/archive/2008/05/15/returning-the-current-time-in-sql-server.aspx" /><id>http://blog.4penny.net/blogs/sqlserver/archive/2008/05/15/returning-the-current-time-in-sql-server.aspx</id><published>2008-05-15T12:10:00Z</published><updated>2008-05-15T12:10:00Z</updated><content type="html">&lt;p&gt;From a recent email:&amp;nbsp;&lt;/p&gt;
&lt;p&gt;I am trying to use SmartList Builder to build a query where a calculation is required showing the number of days an A/R transaction is past due.&amp;nbsp; Obviously, I have the DOCDATE from RM20101 but I need a column that tells me the current date so I can make this comparison…and I am not sure if there is a SQL Server table that I can pull in that shows this information to me.&amp;nbsp; I am pretty certain that there is not a GP table with current date in it just sitting there by default.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Answer:&lt;/p&gt;
&lt;p&gt;&lt;pre style="overflow: scroll; background-color: #f2f2f2;"&gt;&lt;span style="color: Black;background-color: Transparent;font-family: Courier New;font-size: 11px;font-weight: normal;"&gt;&lt;span style="color: Blue;background-color: Transparent;font-family: Courier New;font-size: 11px;font-weight: normal;"&gt;Select&lt;/span&gt; &lt;span style="color: Fuchsia;background-color: Transparent;font-family: Courier New;font-size: 11px;font-weight: normal;"&gt;getdate&lt;/span&gt;(), &lt;span style="color: Fuchsia;background-color: Transparent;font-family: Courier New;font-size: 11px;font-weight: normal;"&gt;convert&lt;/span&gt;(&lt;span style="color: Blue;background-color: Transparent;font-family: Courier New;font-size: 11px;font-weight: normal;"&gt;varchar&lt;/span&gt;(10),&lt;span style="color: Fuchsia;background-color: Transparent;font-family: Courier New;font-size: 11px;font-weight: normal;"&gt;getdate&lt;/span&gt;(),101)&lt;/span&gt;&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;Getdate() returns a date/time, the second part will strip the time&lt;br /&gt;&lt;/p&gt;&lt;img src="http://blog.4penny.net/aggbug.aspx?PostID=1013" width="1" height="1"&gt;</content><author><name>Steve Gray</name><uri>http://blog.4penny.net/members/Steve-Gray.aspx</uri></author></entry></feed>