<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><rss 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:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="2.0">

<channel>
	<title />
	
	<link>http://nelsonsweb.net</link>
	<description />
	<lastBuildDate>Wed, 21 Mar 2012 17:31:49 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/rss+xml" href="http://feeds.feedburner.com/Nelsonswebnet" /><feedburner:info uri="nelsonswebnet" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><item>
		<title>Import Active Directory users into SQL Server</title>
		<link>http://feedproxy.google.com/~r/Nelsonswebnet/~3/3su-Hy6_M3g/</link>
		<comments>http://nelsonsweb.net/2012/03/import-active-directory-users-into-sql-server/#comments</comments>
		<pubDate>Wed, 21 Mar 2012 17:31:14 +0000</pubDate>
		<dc:creator>Matt</dc:creator>
				<category><![CDATA[Tips]]></category>
		<category><![CDATA[ActiveDirectory]]></category>
		<category><![CDATA[powershell]]></category>

		<guid isPermaLink="false">http://nelsonsweb.net/?p=240</guid>
		<description><![CDATA[I needed to import a list of all Active Directory user accounts into a table in SQL Server for a recent project. This project also gave me a perfect opportunity to learn a little bit of powershell. Below chronicles the script that I built. I’m going to skip over a lot of the powershell basics <a href='http://nelsonsweb.net/2012/03/import-active-directory-users-into-sql-server/'>[Keep reading...]</a>]]></description>
			<content:encoded><![CDATA[<p>I needed to import a list of all Active Directory user accounts into a table in SQL Server for a recent project. This project also gave me a perfect opportunity to learn a little bit of powershell. Below chronicles the script that I built. I’m going to skip over a lot of the powershell basics information, as that is available from other sources. For this project, I needed to populate a table with these fields from Active Directory: Display Name, NT username, email address, and office phone.<br />
I used the powershell Get-ADUser cmdlet to get the information out of Active Directory<br />
Before doing anything else, you need to open a powershell command window (Start&#8211;&gt;Run&#8211;&gt;powershell.exe) and import the Powershell ActiveDirectory module:</p>
<pre class="brush: powershell; title: ; notranslate">
PS C:\&gt; Import-Module activedirectory
</pre>
<p>After importing the module, you can learn more about the Get-ADUser cmdlet by using some of these commands</p>
<pre class="brush: powershell; title: ; notranslate">
Get-Help Get-ADUser
Get-Help Get-ADUser -examples
Get-Help Get-ADUser -detailed
</pre>
<p>Examples are great, but I learn better by seeing real results, so lets run a quick query to see what information we get.</p>
<pre class="brush: powershell; title: ; notranslate">
Get-ADUser -filter * -ResultSetSize 1
#Note, I included “-ResultSetSize 1” so that I was not overwhelming the domain controllers while testing.
</pre>
<p>Awesome, I can now see user accounts from Active Directory! The output that I got showed me some of the information that I needed, but I am still missing some pieces (primarily email address and phone number). The “-Properties” option will let you pick additional fields to include in the output. I got a little stuck here briefly, because the Get-ADUser cmdlet names for the properties do not all match the Active Directory field names. To figure out what the appropriate field names were, I ran this:</p>
<pre class="brush: powershell; title: ; notranslate">
Get-ADUser -filter * -ResultSetSize 1 -Properties *
</pre>
<p>Cool, now I can put the fields together to get a shortened list of only what I am looking for:</p>
<pre class="brush: powershell; title: ; notranslate">
Get-ADUser -filter * -ResultSetSize 1 -Properties EmailAddress,OfficePhone
# Note this will return additional fields (DistinguishedName,Enabled,ObjectClass, SID,…)
</pre>
<p>I got a little bit stuck here too, because I was getting too much information. When I got to the point of exporting this data to a CSV file and importing it into SQL Server (coming later), I got hung up because some of the fields did not always have information for my organization. The solution came by using a pipe (SHIFT + \ key) and the Select-Object cmdlet. This let me filter for only the specific columns that I wanted out of Active Directory.</p>
<pre class="brush: powershell; title: ; notranslate">
Get-ADUser -filter * -ResultSetSize 1 -Properties EmailAddress,OfficePhone | Select-Object EmailAddress,OfficePhone,DisplayName,SamAccountName
</pre>
<p>I now see only the 4 columns that I care about. On a larger scale test, I realized that I was returning accounts that I did not want to see (like disabled accounts, Administrative accounts, etc.) I used the –Filter option to include some search criteria here.<br />
Filtering in powershell is a little different than what I am used to. For example, “=” is “-eq” in powershell and “not equal to” or “&lt;&gt;” is “-notlike” in powershell. You can also combine multiple filters by including the entire set in curly brackets { }, individual parameters in parenthesis (), and using the “-and” operator. The Asterisk is the wildcard variable.<br />
For example:</p>
<pre class="brush: powershell; title: ; notranslate">
-Filter {(Name -notlike &quot;*(Administrator)&quot;) -and (Name -notlike &quot;Matt*&quot;) -and (Enabled -eq &quot;True&quot;) }
# I also threw in there where Name is not like Matt*
</pre>
<p>Now that I have only the fields that I want, and I filtered out the users that I don’t want to see, I can start working on importing it into SQL Server. I could have used powershell to insert the records directly into SQL, but I was concerned about latency issues and spamming the domain controllers into a denial-of-service attack. I was working with more than 50,000 Active Directory accounts. I definitely did not want to hold up the domain controllers if there was an issue with the SQL server during the process. Because of this, I decided to export the data as a CSV comma delimited file and then use SSIS to import the data.<br />
Exporting the data to a csv file uses another pipe (SHIFT + \ key) and the export-csv cmdlet. Make sure to put in your appropriate file path to export to</p>
<pre class="brush: powershell; title: ; notranslate">
#Make sure you put your file path between the &lt; &gt;
 | export-csv -path \\\\ADUsersExported.csv -NoTypeInformation -Encoding &quot;UTF8&quot;
</pre>
<h4><span style="text-decoration: underline;">Putting everything together.</span></h4>
<p>Make sure to put in your appropriate file path to export to.<br />
I also took out the “-ResultSetSize” option so that all records were returned.</p>
<pre class="brush: powershell; title: ; notranslate">
#Make sure you put your file path between the &lt; &gt;
Get-ADUser -Filter {(Name -notlike &quot;*(Administrator)&quot;)  -and (Enabled -eq &quot;True&quot;) }  -Properties SamAccountName,DisplayName,EmailAddress,OfficePhone | Select-Object EmailAddress,OfficePhone,DisplayName,SamAccountName | export-csv -path \\\\ADUsersExported.csv -NoTypeInformation -Encoding &quot;UTF8&quot;
</pre>
<p>Once the data was exported to a CSV comma delimited file, I am using SSIS to import it into SQL server. The powershell script and SSIS package are both scheduled to run daily overnight when things should be slower on the servers.</p>
<img src="http://feeds.feedburner.com/~r/Nelsonswebnet/~4/3su-Hy6_M3g" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://nelsonsweb.net/2012/03/import-active-directory-users-into-sql-server/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://nelsonsweb.net/2012/03/import-active-directory-users-into-sql-server/</feedburner:origLink></item>
		<item>
		<title>SQL Tuesday #028 – Jack of All Trades, Master of None</title>
		<link>http://feedproxy.google.com/~r/Nelsonswebnet/~3/CIfKz862Z9k/</link>
		<comments>http://nelsonsweb.net/2012/03/jack-of-all-trades-master-of-none/#comments</comments>
		<pubDate>Tue, 13 Mar 2012 15:00:32 +0000</pubDate>
		<dc:creator>Matt</dc:creator>
				<category><![CDATA[TSQL2sday]]></category>
		<category><![CDATA[#tsql2sday]]></category>

		<guid isPermaLink="false">http://nelsonsweb.net/?p=242</guid>
		<description><![CDATA[This month&#8217;s TSQL Tuesday is hosted by Argenis Fernandez.  This month&#8217;s topic:  &#8221;blog about your experience. Tell us why you specialized, or why you’d like to specialize. If you don’t think that specialization is a good thing, tell us why. Discuss. Argue your point(s).&#8221; ================================================= My first job out of college was a Network Administrator for <a href='http://nelsonsweb.net/2012/03/jack-of-all-trades-master-of-none/'>[Keep reading...]</a>]]></description>
			<content:encoded><![CDATA[<p><a href="http://sqlblog.com/blogs/argenis_fernandez/archive/2012/03/05/t-sql-tuesday-028-jack-of-all-trades-master-of-none.aspx"><img class="alignleft size-full wp-image-161" title="TSQL Tuesday logo" src="http://nelsonsweb.net/wp-content/uploads/2011/09/T-SQLLogo.jpg" alt="" width="145" height="150" /></a>This month&#8217;s <a href="http://sqlblog.com/blogs/argenis_fernandez/archive/2012/03/05/t-sql-tuesday-028-jack-of-all-trades-master-of-none.aspx">TSQL Tuesday</a> is hosted by Argenis Fernandez.  This month&#8217;s topic:  &#8221;blog about your experience. Tell us why you specialized, or why you’d like to specialize. If you don’t think that specialization is a good thing, tell us why. Discuss. Argue your point(s).&#8221;</p>
<p>=================================================</p>
<p>My first job out of college was a Network Administrator for a small non-profit organization.  As the only IT guy in the organization, I was responsible for a lot&#8230;managing servers, planning upgrades, scheduling downtime, email setup/support, network switches, cabling, wireless network access/security, managing data, backing up data, help desk support, desktop pc support, web site design, managing the phone system, building overhead paging, video surveillance system, report design and generation, unjamming printers and copiers, evaluating new applications, and developing custom applications.  The organization has classrooms spread out across the entire county.  Each classroom had various technologies from a PC, to phones, answering machines, and speaker systems.</p>
<p>I definitely could not specialize in any particular area in this position.  On any given day I could have needed to travel 60 miles round trip to fix a problem in one of the outlying classrooms and return to my office prepare data to submit for a federally mandated report.  When people asked me what I did, I would tell them my job was to fix anything that plugged into a wall.  With a non-existent budget, I had to get creative to make things work in the organization.</p>
<p>Through a series of life choices, I moved on to a new company in a new position that focused more on systems and database administration.  This position is definitely a lot more specialized than where I started.  There are now other support groups that I can refer people to for issues with PC&#8217;s, Exchange, networking, phones, etc.</p>
<p>I still think that it is important to keep up on a lot of the basics, especially with SQL server.  People like to blame the database as the problem when often times the solution is not nearly that simple.  Many problems that I encounter on a day-to-day basis are rooted in specialties not directly related to SQL server.  I may not be a specialist in networking, pc repair, or Active Directory administration, but it has been very beneficial to me to have a good working knowledge of these concepts.  There are other people responsible for fixing these things at my current company.  I can usually figure out what the problems is  and direct to the correct support groups fairly quickly with my generalist background.</p>
<img src="http://feeds.feedburner.com/~r/Nelsonswebnet/~4/CIfKz862Z9k" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://nelsonsweb.net/2012/03/jack-of-all-trades-master-of-none/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		<feedburner:origLink>http://nelsonsweb.net/2012/03/jack-of-all-trades-master-of-none/</feedburner:origLink></item>
		<item>
		<title>Running SSMS template explorer from network drive</title>
		<link>http://feedproxy.google.com/~r/Nelsonswebnet/~3/wxm5ojSHYmU/</link>
		<comments>http://nelsonsweb.net/2012/03/running-ssms-template-explorer-from-network-drive/#comments</comments>
		<pubDate>Mon, 12 Mar 2012 14:24:15 +0000</pubDate>
		<dc:creator>Matt</dc:creator>
				<category><![CDATA[Tips]]></category>
		<category><![CDATA[SSMS]]></category>
		<category><![CDATA[tips]]></category>

		<guid isPermaLink="false">http://nelsonsweb.net/?p=244</guid>
		<description><![CDATA[This is a quick one today as a follow-up to my previous post on using the SSMS Template explorer.  While I do like the convenience of using the template explorer to store frequently used scripts, one of my biggest  complaints was the fact that all the scripts are buried several directories down under the C:\users directory (windows <a href='http://nelsonsweb.net/2012/03/running-ssms-template-explorer-from-network-drive/'>[Keep reading...]</a>]]></description>
			<content:encoded><![CDATA[<p>This is a quick one today as a follow-up to my previous post on using the <a title="SSMS Template explorer" href="http://nelsonsweb.net/2011/09/ssms-template-explorer/">SSMS Template explorer</a>.  While I do like the convenience of using the template explorer to store frequently used scripts, one of my biggest  complaints was the fact that all the scripts are buried several directories down under the C:\users directory (windows 7).</p>
<p>Carl Demelo shared <a href="http://www.sqlservercentral.com/articles/Management+Studio+(SSMS)/75955/">an awesome way to move your template directory</a> to a different directory on SQL Server Central.  This solution will only work on Windows 7 using the new shell command <span style="text-decoration: underline;">mklink</span>.</p>
<p>I tried it out to move my template directory to a network drive that gets backed up on a regular basis.  It worked perfect, thanks Carl!</p>
<img src="http://feeds.feedburner.com/~r/Nelsonswebnet/~4/wxm5ojSHYmU" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://nelsonsweb.net/2012/03/running-ssms-template-explorer-from-network-drive/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://nelsonsweb.net/2012/03/running-ssms-template-explorer-from-network-drive/</feedburner:origLink></item>
		<item>
		<title>T_SQL Tuesday #25: Sharing Tricks</title>
		<link>http://feedproxy.google.com/~r/Nelsonswebnet/~3/6bqtLMoPZPw/</link>
		<comments>http://nelsonsweb.net/2011/12/t_sql-tuesday-25-sharing-tricks/#comments</comments>
		<pubDate>Tue, 13 Dec 2011 15:00:38 +0000</pubDate>
		<dc:creator>Matt</dc:creator>
				<category><![CDATA[Tips]]></category>
		<category><![CDATA[TSQL2sday]]></category>
		<category><![CDATA[#tsql2sday]]></category>
		<category><![CDATA[tips]]></category>

		<guid isPermaLink="false">http://nelsonsweb.net/?p=227</guid>
		<description><![CDATA[The topic for this month’s TSQL Tuesday, hosted by Allen White, is an invitation to share your tricks.  Before I get into my trick to share, I wanted to mention that Allen is a pretty awesome speaker too.  I got to see his session “Gather SQL Server Performance Data with Powershell” at the SQL Saturday <a href='http://nelsonsweb.net/2011/12/t_sql-tuesday-25-sharing-tricks/'>[Keep reading...]</a>]]></description>
			<content:encoded><![CDATA[<p>The topic for this month’s TSQL Tuesday, hosted by Allen White, <a href="http://sqlblog.com/blogs/allen_white/archive/2011/12/05/t-sql-tuesday-025-invitation-to-share-your-tricks.aspx">is an invitation to share your tricks</a>.  Before I get into my trick to share, I wanted to mention that Allen is a pretty awesome speaker too.  I got to see his session “Gather SQL Server Performance Data with Powershell” at the SQL Saturday in Columbus earlier this year.  Allen is really excited about SQL Server and the cool things you can do with Powershell.</p>
<p>Now for my trick, I have a view that was created to help write more dynamic rolling sql queries and reports in my organization.  I’m not sure who the original author of the script is, as it has been passed around and modified several times.  I thought I would share it here in the hopes that it helps someone else someday.  If you’re the original author or know who is, please let me know so I can give you due credit.</p>
<p>This view defines a bunch of different date parameters compared to the current date, including:</p>
<ul>
<li>TODAY_BEGIN</li>
<li>TODAY_END</li>
<li>YESTERDAY_BEGIN</li>
<li>YESTERDAY_END</li>
<li>DAY_BEFORE_YESTERDAY_BEGIN</li>
<li>DAY_BEFORE_YESTERDAY_END</li>
<li>SUNDAY_WEEK_BEGIN</li>
<li>SUNDAY_WEEK_END</li>
<li>MONDAY_WEEK_BEGIN</li>
<li>MONDAY_WEEK_END</li>
<li>PREVIOUS_SUNDAY_WEEK_BEGIN</li>
<li>PREVIOUS_SUNDAY_WEEK_END</li>
<li>PREVIOUS_MONDAY_WEEK_BEGIN</li>
<li>PREVIOUS_MONDAY_WEEK_END</li>
<li>MONTH_BEGIN</li>
<li>MONTH_END</li>
<li>YESTERDAYS_MONTH_BEGIN</li>
<li>YESTERDAYS_MONTH_END</li>
<li>PREVIOUS_MONTH_BEGIN</li>
<li>PREVIOUS_MONTH_END</li>
<li>SECOND_PREVIOUS_MONTH_BEGIN</li>
<li>SECOND_PREVIOUS_MONTH_END</li>
<li>THIRD_PREVIOUS_MONTH_BEGIN</li>
<li>THIRD_PREVIOUS_MONTH_END</li>
<li>FOURTH_PREVIOUS_MONTH_BEGIN</li>
<li>FOURTH_PREVIOUS_MONTH_END</li>
<li>TWELTH_PREVIOUS_MONTH_BEGIN</li>
<li>TWELTH_PREVIOUS_MONTH_END</li>
<li>PREVIOUS_SIXTH_MONDAY_WEEK_BEGIN</li>
<li>PREVIOUS_SIXTH_MONDAY_WEEK_END</li>
<li>PREVIOUS_SIXTH_SUNDAY_WEEK_BEGIN</li>
<li>PREVIOUS_SIXTH_SUNDAY_WEEK_END</li>
<li>NEXT_MONTH_BEGIN</li>
<li>NEXT_MONTH_END</li>
</ul>
<p>You can take a quick look at the result returned from this view.  After creating the view (script included below), run:</p>
<pre class="brush: sql; title: ; notranslate">
SELECT  *
FROM    vw_date_ranges
</pre>
<p>With these columns defined, you can easily query a database table looking for rows based off of a date by cross joining this view and the adding the date columns to the where clause.  For example, if you want to see all orders for “This Week”, you can run a query similar to:</p>
<pre class="brush: sql; title: ; notranslate">
SELECT SalesOrderID,
       OrderDate,
       SalesOrderNumber,
       PurchaseOrderNumber,
       CustomerID,
       TotalDue
FROM   Sales.SalesOrderHeader
       CROSS JOIN vw_date_ranges
WHERE  Sales.SalesOrderHeader.OrderDate &gt; vw_date_ranges.SUNDAY_WEEK_BEGIN
</pre>
<p>Or if you want to see all orders for &#8220;Last Month&#8221;, you can run a query similar to:</p>
<pre class="brush: sql; title: ; notranslate">
SELECT SalesOrderID,
       OrderDate,
       SalesOrderNumber,
       PurchaseOrderNumber,
       CustomerID,
       TotalDue
FROM   Sales.SalesOrderHeader
       CROSS JOIN vw_date_ranges
WHERE  Sales.SalesOrderHeader.OrderDate &gt;= vw_date_ranges.PREVIOUS_MONTH_BEGIN
       AND Sales.SalesOrderHeader.OrderDate &lt; vw_date_ranges.MONTH_BEGIN
</pre>
<p>Using this method helps me keep my sql query clean, and provides a rolling date range on queries and reports.</p>
<p><a href="http://nelsonsweb.net/wp-content/uploads/2011/12/vw_date_ranges.zip">Download the script here</a></p>
<pre class="brush: sql; title: ; notranslate">

SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

CREATE VIEW [dbo].[vw_date_ranges]
(TODAY_BEGIN, TODAY_END, YESTERDAY_BEGIN, YESTERDAY_END, DAY_BEFORE_YESTERDAY_BEGIN,
DAY_BEFORE_YESTERDAY_END, SUNDAY_WEEK_BEGIN, SUNDAY_WEEK_END, MONDAY_WEEK_BEGIN, MONDAY_WEEK_END,
PREVIOUS_SUNDAY_WEEK_BEGIN, PREVIOUS_SUNDAY_WEEK_END, PREVIOUS_MONDAY_WEEK_BEGIN, PREVIOUS_MONDAY_WEEK_END, MONTH_BEGIN,
MONTH_END, YESTERDAYS_MONTH_BEGIN, YESTERDAYS_MONTH_END, PREVIOUS_MONTH_BEGIN, PREVIOUS_MONTH_END,
SECOND_PREVIOUS_MONTH_BEGIN, SECOND_PREVIOUS_MONTH_END, THIRD_PREVIOUS_MONTH_BEGIN, THIRD_PREVIOUS_MONTH_END, FOURTH_PREVIOUS_MONTH_BEGIN,
FOURTH_PREVIOUS_MONTH_END, TWELTH_PREVIOUS_MONTH_BEGIN, TWELTH_PREVIOUS_MONTH_END, PREVIOUS_SIXTH_MONDAY_WEEK_BEGIN, PREVIOUS_SIXTH_MONDAY_WEEK_END,
PREVIOUS_SIXTH_SUNDAY_WEEK_BEGIN, PREVIOUS_SIXTH_SUNDAY_WEEK_END,NEXT_MONTH_BEGIN,NEXT_MONTH_END)
AS
select DATEADD(dd, DATEDIFF(dd,0,getdate()), 0)                                TODAY_BEGIN,
dateadd(ms,-3,DATEADD(dd, DATEDIFF(dd,0,getdate()+ 1 ), 0)) - .000011574        TODAY_END,
DATEADD(dd, DATEDIFF(dd,0,getdate()), -1)                                       YESTERDAY_BEGIN,
dateadd(ms,-3,DATEADD(dd, DATEDIFF(dd,0,getdate()  ), 0)) - .000011574          YESTERDAY_END,
DATEADD(dd, DATEDIFF(dd,0,getdate()), -2)                                       DAY_BEFORE_YESTERDAY_BEGIN,
dateadd(ms,-3,DATEADD(dd, DATEDIFF(dd,0,getdate()  ), -1)) - .000011574         DAY_BEFORE_YESTERDAY_END,
-- Relative Dates - Weeks
DATEADD(wk, DATEDIFF(wk,0,getdate()), -1)                        SUNDAY_WEEK_BEGIN,
DATEADD(wk, DATEDIFF(wk,0,getdate()), -1) + 6.999988426          SUNDAY_WEEK_END,
DATEADD(wk, DATEDIFF(wk,0,getdate()), 0)                         MONDAY_WEEK_BEGIN,
DATEADD(wk, DATEDIFF(wk,0,getdate()), 0)  + 7.999988426          MONDAY_WEEK_END,
DATEADD(wk, DATEDIFF(wk,0,getdate()), -8)                        PREVIOUS_SUNDAY_WEEK_BEGIN,
DATEADD(wk, DATEDIFF(wk,0,getdate()), -8) + 6.999988426          PREVIOUS_SUNDAY_WEEK_END,
DATEADD(wk, DATEDIFF(wk,0,getdate()), -7)                        PREVIOUS_MONDAY_WEEK_BEGIN,
DATEADD(wk, DATEDIFF(wk,0,getdate()), -7) + 7.999988426          PREVIOUS_MONDAY_WEEK_END,
-- Relative Dates - Months
dateadd(mm,datediff(mm,0,getdate()),0)                                                    MONTH_BEGIN,
dateadd(ms,-3,DATEADD(mm, DATEDIFF(m,0,getdate()  )+1, 0)) - .000011574                   MONTH_END,
dateadd(mm,datediff(mm,0,getdate() - 1),0)                                                YESTERDAYS_MONTH_BEGIN,
dateadd(ms,-3,DATEADD(mm, DATEDIFF(m,0,getdate() - 1 )+1, 0)) - .000011574                YESTERDAYS_MONTH_END,
DATEADD(mm, DATEDIFF(mm,0,getdate()  )-1, 0)                                              PREVIOUS_MONTH_BEGIN,
dateadd(ms,-3,DATEADD(mm, DATEDIFF(mm,0,getdate()  ), 0)) - .000011574                    PREVIOUS_MONTH_END,
DATEADD(mm, DATEDIFF(mm,0,getdate()  )-2, 0)                                              SECOND_PREVIOUS_MONTH_BEGIN,
dateadd(ms,-3,DATEADD(mm, DATEDIFF(mm,0,getdate()  )-1, 0)) - .000011574                  SECOND_PREVIOUS_MONTH_END,
DATEADD(mm, DATEDIFF(mm,0,getdate()  )-3, 0)                                              THIRD_PREVIOUS_MONTH_BEGIN,
dateadd(ms,-3,DATEADD(mm, DATEDIFF(mm,0,getdate()  )-2, 0)) - .000011574                  THIRD_PREVIOUS_MONTH_END,
DATEADD(mm, DATEDIFF(mm,0,getdate()  )-4, 0)                                              FOURTH_PREVIOUS_MONTH_BEGIN,
dateadd(ms,-3,DATEADD(mm, DATEDIFF(mm,0,getdate()  )-3, 0)) - .000011574                  FOURTH_PREVIOUS_MONTH_END,
DATEADD(mm, DATEDIFF(mm,0,getdate()  )-12, 0)                                              TWELTH_PREVIOUS_MONTH_BEGIN,
dateadd(ms,-3,DATEADD(mm, DATEDIFF(mm,0,getdate()  )-11, 0)) - .000011574                  TWELTH_PREVIOUS_MONTH_END,
-- Added 2/23/09 These will be used in a claim audit report that looks at data from 6 weeks prior.
DATEADD(wk, DATEDIFF(wk,0,getdate()  )-6, 0)  as   PREVIOUS_SIXTH_MONDAY_WEEK_BEGIN,
DATEADD(wk, DATEDIFF(wk,0,getdate()  )-6, 0) + 7.999988426  as PREVIOUS_SIXTH_MONDAY_WEEK_END,
DATEADD(wk, DATEDIFF(wk,0,getdate()  )-6, -1) as   PREVIOUS_SIXTH_SUNDAY_WEEK_BEGIN,
DATEADD(wk, DATEDIFF(wk,0,getdate()  )-6, -1) + 6.999988426  as PREVIOUS_SIXTH_SUNDAY_WEEK_END,
DATEADD(mm, DATEDIFF(mm,0,getdate()  )+1, 0)                                              NEXT_MONTH_BEGIN,
dateadd(ms,-3,DATEADD(mm, DATEDIFF(mm,0,getdate()  )+2, 0)) + .000011574                    NEXT_MONTH_END
</pre>
<img src="http://feeds.feedburner.com/~r/Nelsonswebnet/~4/6bqtLMoPZPw" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://nelsonsweb.net/2011/12/t_sql-tuesday-25-sharing-tricks/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		<feedburner:origLink>http://nelsonsweb.net/2011/12/t_sql-tuesday-25-sharing-tricks/</feedburner:origLink></item>
		<item>
		<title>Fixing orphaned users</title>
		<link>http://feedproxy.google.com/~r/Nelsonswebnet/~3/OOuEJVjwyX4/</link>
		<comments>http://nelsonsweb.net/2011/10/fixing-orphaned-users/#comments</comments>
		<pubDate>Tue, 18 Oct 2011 14:00:52 +0000</pubDate>
		<dc:creator>Matt</dc:creator>
				<category><![CDATA[Fixes]]></category>
		<category><![CDATA[Tips]]></category>
		<category><![CDATA[security]]></category>
		<category><![CDATA[tsql]]></category>

		<guid isPermaLink="false">http://nelsonsweb.net/?p=215</guid>
		<description><![CDATA[Whenever I restore a production database to a development server, I often end up with orphaned users. You can see in the screen shot below that username matt has no login associated with it. An account becomes orphaned when there is a user account with security rights in the database that is not linked to <a href='http://nelsonsweb.net/2011/10/fixing-orphaned-users/'>[Keep reading...]</a>]]></description>
			<content:encoded><![CDATA[<p>Whenever I restore a production database to a development server, I often end up with orphaned users. You can see in the screen shot below that username <span style="text-decoration: underline;"><strong>matt</strong></span> has no login associated with it.</p>
<p><a href="http://nelsonsweb.net/wp-content/uploads/2011/10/orphaned1.png"><img class="size-full wp-image-219 alignnone" title="orphaned1" src="http://nelsonsweb.net/wp-content/uploads/2011/10/orphaned1.png" alt="" width="704" height="237" /></a></p>
<p>An account becomes orphaned when there is a user account with security rights in the database that is not linked to a user account that can log in to the server.  This happens because SQL logins with the same username have different SID&#8217;s on different servers.  It is not a problem for Active Directory logins because the SID is stored in Active Directory.</p>
<p>Once an account becomes orphaned, it is a pretty easy fix:</p>
<pre class="brush: sql; title: ; notranslate">
USE &lt;database name&gt;
ALTER USER &lt;username&gt; WITH LOGIN = &lt;username&gt;
</pre>
<p>But it&#8217;s still a pain to remember to run this code to reset the logins.  I usually forget, and the scratch my head for a minute to figure out why the application won&#8217;t connect to the development database anymore.</p>
<h4><span style="text-decoration: underline;">Fix it once and for all</span></h4>
<p>Microsoft has a handy script to fix orphaned users (<a href="http://support.microsoft.com/kb/918992">link</a>).  Download and run the script on your production server to create two stored procedures: sp_hexadecimal and sp_help_revlogin.</p>
<p>Then run:</p>
<pre class="brush: sql; title: ; notranslate">
EXEC sp_help_revlogin
</pre>
<p>Run the output from this procedure against your development server to create the appropriate logins with the correct username/password and SID.</p>
<p>Ever since I ran this, I have not had any more orphaned users when restoring databases back to dev.</p>
<img src="http://feeds.feedburner.com/~r/Nelsonswebnet/~4/OOuEJVjwyX4" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://nelsonsweb.net/2011/10/fixing-orphaned-users/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://nelsonsweb.net/2011/10/fixing-orphaned-users/</feedburner:origLink></item>
		<item>
		<title>T-SQL Tuesday #23: Fixing Joined Views</title>
		<link>http://feedproxy.google.com/~r/Nelsonswebnet/~3/QaepGUqfbZU/</link>
		<comments>http://nelsonsweb.net/2011/10/t-sql-tuesday-23-joins/#comments</comments>
		<pubDate>Tue, 04 Oct 2011 13:00:29 +0000</pubDate>
		<dc:creator>Matt</dc:creator>
				<category><![CDATA[TSQL2sday]]></category>
		<category><![CDATA[#tsql2sday]]></category>

		<guid isPermaLink="false">http://nelsonsweb.net/?p=184</guid>
		<description><![CDATA[This month&#8217;s TSQL Tuesday topic, hosted by Stuart Ainsworth, is Joins.  I am going to share a story of a performance improvement that I made with joined views. One of the main vendor-built applications that I support has views built on top of tables.  Unfortunately that&#8217;s not the end of the story.  These views are <a href='http://nelsonsweb.net/2011/10/t-sql-tuesday-23-joins/'>[Keep reading...]</a>]]></description>
			<content:encoded><![CDATA[<p><a href="http://codegumbo.com/index.php/2011/09/27/tsql2sday-t-sql-tuesday-23early-edition/"><img class="alignleft size-full wp-image-161" title="TSQL Tuesday logo" src="http://nelsonsweb.net/wp-content/uploads/2011/09/T-SQLLogo.jpg" alt="" width="145" height="150" /></a>This month&#8217;s TSQL Tuesday topic, hosted by Stuart Ainsworth, is Joins.  I am going to share a story of a performance improvement that I made with joined views.</p>
<p>One of the main vendor-built applications that I support has views built on top of tables.  Unfortunately that&#8217;s not the end of the story.  These views are built on top of views, which join together other views, which link back to the database tables.  In all the training materials provided by the vendor, they say to *always* use the views when writing a report on the data and never directly query the table.</p>
<p>Using the vendor provided views generally works out OK and performs reasonably well.  One particular report I wrote kept bugging me due to how long it took to run (several minutes each time). compared to how much data was actually returned.  So I started looking at the execution times and the query plans.  Note, I took the screenshots below using the fantastic free tool from SQL Sentry, <a href="http://www.sqlsentry.com/plan-explorer/sql-server-query-view.asp">SQL Sentry Plan Explorer</a>.</p>
<p>This report needed to join 5 tables to get the data that I needed.  Using the vendor provided views, here is the join diagram I started out with:</p>
<p><a href="http://nelsonsweb.net/wp-content/uploads/2011/09/join1.png"><img class="size-large wp-image-185 alignnone" title="join1" src="http://nelsonsweb.net/wp-content/uploads/2011/09/join1-1024x323.png" alt="" width="695" height="219" /></a></p>
<p>You can see that the vendor views are joining together a lot more hidden tables (table &amp; field names blurred to protect the innocent) than the 5 I actually need.  The nested views are even hitting the same tables more than once.</p>
<p>Here is the original query plan:</p>
<p><a href="http://nelsonsweb.net/wp-content/uploads/2011/09/plan1.png"><img class="size-large wp-image-186 alignnone" title="plan1" src="http://nelsonsweb.net/wp-content/uploads/2011/09/plan1-1024x493.png" alt="" width="695" height="334" /></a></p>
<p>You can&#8217;t see it in the screen shot, but one of the thick lines in the middle is representing 23 million rows!</p>
<p>OK, time to pull out the detective hat.  I decided to rewrite the query using only the base tables.  I had to do a bit of extra work with things like UTC datetime vs. local time which the views converted.  After the rewrite, the join diagram looked like this:</p>
<p><a href="http://nelsonsweb.net/wp-content/uploads/2011/10/join2.png"><img class="size-full wp-image-189 alignnone" title="join2" src="http://nelsonsweb.net/wp-content/uploads/2011/10/join2.png" alt="" width="550" height="176" /></a></p>
<p>Here is the final query plan:</p>
<p><a href="http://nelsonsweb.net/wp-content/uploads/2011/10/plan2.png"><img class="size-large wp-image-190 alignnone" title="plan2" src="http://nelsonsweb.net/wp-content/uploads/2011/10/plan2-1024x127.png" alt="" width="695" height="86" /></a></p>
<p>The highest number of rows coming through is about 11,000.  A far cry from the 23 million rows in the original query! The execution plan also looks a lot leaner than what I started with as well.</p>
<p>The original query was running with an average CPU time = 26062 ms, and an average elapsed time = 26424 ms.<br />
My rewritten query is now running with an average CPU time = 0 ms, and an average elapsed time = 266 ms.</p>
<p>Looking at the actual execution plan, SSMS is prompting me that there is a missing index for my new query, and there is still a Clustered Index Scan that accounts for 87% of the query.   I may look into that more at a later date, but for now I am very happy running a query in a couple of seconds that used to take several minutes. I don&#8217;t think it&#8217;s really worth the extra effort to try to shave another 100 ms off of a query that completes in under 300 ms.</p>
<p>The vendor supplied nested views were each joining together multiple views and tables, which was causing a lot of extra and unnecessary bloat in my query.  An hour of work and cutting out all the bloat made a huge difference in this particular report&#8217;s run time.</p>
<h3>And the users rejoice at how fast their report now runs!</h3>
<img src="http://feeds.feedburner.com/~r/Nelsonswebnet/~4/QaepGUqfbZU" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://nelsonsweb.net/2011/10/t-sql-tuesday-23-joins/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		<feedburner:origLink>http://nelsonsweb.net/2011/10/t-sql-tuesday-23-joins/</feedburner:origLink></item>
		<item>
		<title>Creating a new template</title>
		<link>http://feedproxy.google.com/~r/Nelsonswebnet/~3/bIEj0Wr9nPg/</link>
		<comments>http://nelsonsweb.net/2011/09/creating-a-new-template/#comments</comments>
		<pubDate>Thu, 22 Sep 2011 16:55:55 +0000</pubDate>
		<dc:creator>Matt</dc:creator>
				<category><![CDATA[Tips]]></category>
		<category><![CDATA[SSMS]]></category>
		<category><![CDATA[tips]]></category>
		<category><![CDATA[tsql]]></category>

		<guid isPermaLink="false">http://nelsonsweb.net/?p=173</guid>
		<description><![CDATA[Today I am continuing from my introduction to SSMS Template Explorer.  Part 2 today is a quick look at creating your own templates.  I mentioned in the previous post that if you delete one of the Microsoft provided templates, it will be recreated when you next launch SSMS.  Another thing of note: if you make <a href='http://nelsonsweb.net/2011/09/creating-a-new-template/'>[Keep reading...]</a>]]></description>
			<content:encoded><![CDATA[<p>Today I am continuing from my introduction to <a title="SSMS Template explorer" href="http://nelsonsweb.net/2011/09/ssms-template-explorer/">SSMS Template Explorer</a>.  Part 2 today is a quick look at creating your own templates.  I mentioned in the previous post that if you delete one of the Microsoft provided templates, it will be recreated when you next launch SSMS.  Another thing of note: if you make a change to any of the default templates, those changes will keep when you next launch SSMS.  In other words, changes do not get overwritten.  My personal preference is to make a new template and not editing the Microsoft supplied template even though any edits that you make stick in the template.</p>
<h4>Create the template file</h4>
<ol>
<li>First right-click on the root node in Template Explorer labeled &#8220;SQL Server Templates&#8221;</li>
<li>Select New, and then Folder</li>
<li>Name your folder.  I generally start my folder names with a period so that they get sorted at the top of the list.  for example: &#8220;.Admin&#8221;</li>
<li>Once you create your folder, Right click on that folder name.</li>
<li>Select New, and then Template</li>
<li>Name your template whatever makes sense to you.</li>
</ol>
<h4>Edit the template file</h4>
<p>Now that your template is created, the next logical step is to double-click it to open it.  If you do that, you will see a blank query open up in the main window.  This is not exactly what you want.  Instead, right-click on your template and then click Edit.</p>
<p>Now when the blank query opens in the main window, it should have the template name in the query tab at the top.  By going this route, when you save the query your script will get saved into the template file.</p>
<p>The first thing I usually do is start with a quick header.  I will put some general information about what the template is for, the source if I copied it from a blog post somewhere, and the shortcut key to specify values for the template because I can never seem to remember them.</p>
<pre class="brush: sql; title: ; notranslate">
--------------------------------
-- Template Header
-- It's here so I remember what I am using this piece of script for
-- Created by Matt Nelson, 9/15/2011
--
-- Press CTRL + SHIFT + M to fill in variables (because I can never remember the key combination)
--------------------------------
</pre>
<p>I can add my script now that my header is in place.  There is a special syntax that you can use to use the CTRL+SHIFT+M shortcut to fill in blanks.  I am going to steal Microsoft&#8217;s Backup Database template here to show you the syntax</p>
<pre class="brush: sql; title: ; notranslate">

BACKUP DATABASE sysname, Database_Name&gt;
TO  DISK = N'sysname, Database_Name&gt;.bak'
WITH
NOFORMAT,
COMPRESSION,
NOINIT,
NAME = N'sysname, Database_Name&gt;-Full Database Backup',
SKIP,
STATS = 10;
GO
</pre>
<p>When you want to make a variable placeholder in your script you will put a 3 part variable enclosed between the greater than and less than symbols: <strong>&lt;Parameter,Type,Value&gt;</strong>  like: <strong>sysname, Database_Name&gt;</strong> .</p>
<ul>
<li>Parameter is basically the variable name.</li>
<li>Type is a placeholder for the of variable.  There are no constraints around the type like there are with a database table column.  I generally leave this blank.</li>
<li>Value can also be blank, or you can make it a sample for yourself.</li>
</ul>
<p>Once you get your script all set up, don&#8217;t forget to save it.  The next time you want to run it, all you have to do is double-click on it in Template Explorer.</p>
<img src="http://feeds.feedburner.com/~r/Nelsonswebnet/~4/bIEj0Wr9nPg" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://nelsonsweb.net/2011/09/creating-a-new-template/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://nelsonsweb.net/2011/09/creating-a-new-template/</feedburner:origLink></item>
		<item>
		<title>T-SQL Tuesday #22 Data Presentation</title>
		<link>http://feedproxy.google.com/~r/Nelsonswebnet/~3/GDdFVV_GnoE/</link>
		<comments>http://nelsonsweb.net/2011/09/t-sql-tuesday-22-data-presentation/#comments</comments>
		<pubDate>Tue, 13 Sep 2011 11:00:42 +0000</pubDate>
		<dc:creator>Matt</dc:creator>
				<category><![CDATA[TSQL2sday]]></category>
		<category><![CDATA[#tsql2sday]]></category>
		<category><![CDATA[cognos]]></category>
		<category><![CDATA[reporting]]></category>

		<guid isPermaLink="false">http://nelsonsweb.net/?p=159</guid>
		<description><![CDATA[This month&#8217;s TSQL Tuesday topic: Data Presentation. I am not going to show any code this month, and I am also going to veer off the topic of SQL server slightly. My company does a lot of reporting though Cognos.  The nice thing about Cognos is that it is platform independent.  Once a connection is <a href='http://nelsonsweb.net/2011/09/t-sql-tuesday-22-data-presentation/'>[Keep reading...]</a>]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.sqlservercentral.com/blogs/pearlknows/archive/2011/09/06/invitation-for-t-sql-tuesday-22-data-presentation.aspx"><img class="alignleft size-full wp-image-161" title="TSQL Tuesday logo" src="http://nelsonsweb.net/wp-content/uploads/2011/09/T-SQLLogo.jpg" alt="" width="145" height="150" /></a>This month&#8217;s TSQL Tuesday topic: <a href="http://www.sqlservercentral.com/blogs/pearlknows/archive/2011/09/06/invitation-for-t-sql-tuesday-22-data-presentation.aspx">Data Presentation</a>.</p>
<p>I am not going to show any code this month, and I am also going to veer off the topic of SQL server slightly.</p>
<p>My company does a lot of reporting though Cognos.  The nice thing about Cognos is that it is platform independent.  Once a connection is made to an Oracle, MSSQL, or even MySQL database, the presentation looks the same to a report developer.  The end user goes to the URL for cognos and runs their report.  They may not even know what application or technical backend is supplying the data.</p>
<p>We have LOTS of reports that get run across the enterprise.  We also probably have a couple hundred report developers that write reports with varying degrees of frequency.  I&#8217;m sure you can imagine that without any standards no two reports would look similar and end users would not know how to use or interpret the information that they get out of a report.  Hence why data presentation is so important.</p>
<p>There are several standards that have to be met in our environment in order for a report to be published for end users.  While I don&#8217;t think it would be appropriate for me to show you any screenshots, I can summarize some of the general rules here.</p>
<ol>
<li>All reports must use the corporate header and footer.  Information included must contain the business unit for the report, Title of the report, corporate logo, confidentiality statement, page numbers, and telling how to best view the report (ie: html, pdf, Excel, etc.)</li>
<li>The last page of the report must be the standard documentation page.  This page has a table with specific information recorded about the report including:</li>
<ul>
<li><strong>Report Purpose</strong>: A general description of what the report is and how it should be used.<br />
<strong></strong></li>
<li><strong>Data Source</strong>: name of the server, database, or application where the data in the report came from.</li>
<li><strong>Author</strong>: who wrote the report, and how to contact them with questions.</li>
<li><strong>Security</strong>: Security requirements of the report.  Does it contain confidential information? Who or what security groups are allowed to run the report.</li>
<li><strong>Business Logic</strong>: List of information that may be critical to interpreting the report.  For example, &#8220;Annual sales figures are calculated based on the fiscal year of July 1 to June 30 in this report&#8221;.  Also list any abbreviations that everyone may not know.  For example, &#8220;AHG = Average Height by Gender (I made that up)&#8221;.</li>
<li><strong>Assumptions</strong>: What assumptions, if any, were made while writing the report.   I have also seen some report authors insert any user defined variables here.  This way when someone runs a report and they think that it is wrong, the report author can see exactly what values the user entered into the prompt boxes as a point to start troubleshooting.</li>
</ul>
</ol>
<p>The documentation page on a report becomes a valuable tool for anyone trying to understand a report and also very useful for someone who is troubleshooting a report.  Of course it is also helpful when an end user does not delete the documentation page&#8230;..</p>
<img src="http://feeds.feedburner.com/~r/Nelsonswebnet/~4/GDdFVV_GnoE" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://nelsonsweb.net/2011/09/t-sql-tuesday-22-data-presentation/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		<feedburner:origLink>http://nelsonsweb.net/2011/09/t-sql-tuesday-22-data-presentation/</feedburner:origLink></item>
		<item>
		<title>UDA-SQL-0283 Metadata describing column does not match results from database</title>
		<link>http://feedproxy.google.com/~r/Nelsonswebnet/~3/cKpnULfeL8s/</link>
		<comments>http://nelsonsweb.net/2011/09/uda-sql-0283-metadata-describing-column-does-not-match-results-from-database/#comments</comments>
		<pubDate>Fri, 09 Sep 2011 16:00:38 +0000</pubDate>
		<dc:creator>Matt</dc:creator>
				<category><![CDATA[Fixes]]></category>
		<category><![CDATA[cognos]]></category>
		<category><![CDATA[fixes]]></category>
		<category><![CDATA[mysql]]></category>

		<guid isPermaLink="false">http://nelsonsweb.net/?p=155</guid>
		<description><![CDATA[In my current job, I have a MySQL database server that I am responsible for.  We also run some reporting through Cognos against this server.  I ran across a problem while testing reports on an upgrade to Cognos 10.  I thought I would share the solution here in case it helps someone else out someday. <a href='http://nelsonsweb.net/2011/09/uda-sql-0283-metadata-describing-column-does-not-match-results-from-database/'>[Keep reading...]</a>]]></description>
			<content:encoded><![CDATA[<p>In my current job, I have a MySQL database server that I am responsible for.  We also run some reporting through Cognos against this server.  I ran across a problem while testing reports on an upgrade to Cognos 10.  I thought I would share the solution here in case it helps someone else out someday.</p>
<p>I kept running into error messages while testing the Cognos reports that hit the MySQL database:</p>
<ul>
<li>RQP-DEF-0177 An error occurred while performing operation &#8216;sqlOpenResult&#8217; status=&#8217;-28&#8242;.</li>
<li>UDA-SQL-0114 The cursor supplied to the operation &#8220;sqlOpenResult&#8221; is inactive.</li>
<li>UDA-SQL-0283 Metadata describing &lt;column name&gt; does not match results from the database.</li>
</ul>
<p>I then opened up Cognos Framework Manager to look at the package.  The weird thing is that I was able to run a Test Sample and see data return in Framework Manager.  However the same data item was throwing errors in Report Studio.  When I looked at the data items in Framework Manager, they had a data type of nVarChar.</p>
<h5>Time to bring in the big guns</h5>
<p>I started working with our Cognos support group to figure out what was going on.  They were able to edit the definition of one of the data queries in Framework Manager.  When the updated the data item, the data type of the text columns changed from &#8220;nVarChar&#8221; to &#8220;Character Length 16&#8243;.  Once they made the change and updated the package, the reports started running again in Report Studio.</p>
<p>Woohoo, problem solved!</p>
<p>Oh wait, I spoke too soon&#8230;I went back in to Framework Manager to repeat our support group&#8217;s steps against other query items to update the whole package.  Unfortunately when I updated any of the data queries, the data type kept changing back to &#8220;nVarChar&#8221; and the reports threw errors again.  I even tried to re-update the data item that our support group fixed.  When I made my edit, the reports broke again.</p>
<h5>The Solution</h5>
<p>Long story short, and after 2 weeks and plenty of headaches&#8230;.I had a different version of the MySQL ODBC driver installed on my PC from what our Cognos support group did.  I changed the driver version from 5.1 to 3.51, and finally it worked!  I figured that the newer driver would be better, but apparently Cognos 10 Framework Manager has a problem with the MySQL ODBC 5.1 driver, and needs the 3.51 driver instead.</p>
<p>With the older driver installed on my system, I was able to update the Framework Manager package and then pull back data error free in Report Studio.</p>
<p>One other thing of note: after I update the query subject in the Physical Layer in Framework Manager, the links broke in the Presentation layer.  I had to go back into the Presentation Layer to update the links there as well.</p>
<img src="http://feeds.feedburner.com/~r/Nelsonswebnet/~4/cKpnULfeL8s" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://nelsonsweb.net/2011/09/uda-sql-0283-metadata-describing-column-does-not-match-results-from-database/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://nelsonsweb.net/2011/09/uda-sql-0283-metadata-describing-column-does-not-match-results-from-database/</feedburner:origLink></item>
		<item>
		<title>SSMS Template explorer</title>
		<link>http://feedproxy.google.com/~r/Nelsonswebnet/~3/mrCZOu1S7i0/</link>
		<comments>http://nelsonsweb.net/2011/09/ssms-template-explorer/#comments</comments>
		<pubDate>Fri, 09 Sep 2011 14:00:05 +0000</pubDate>
		<dc:creator>Matt</dc:creator>
				<category><![CDATA[Tips]]></category>
		<category><![CDATA[SSMS]]></category>
		<category><![CDATA[tips]]></category>

		<guid isPermaLink="false">http://nelsonsweb.net/?p=133</guid>
		<description><![CDATA[I have used several different methods for collecting SQL scripts (both that I have written, and have borrowed from others) to reuse.  A few that come to mind include: 1. saving the scripts in individual .sql files somewhere on my hard drive, 2. storing the scripts as an individual page in Microsoft Onenote. 3. saving <a href='http://nelsonsweb.net/2011/09/ssms-template-explorer/'>[Keep reading...]</a>]]></description>
			<content:encoded><![CDATA[<p><a href="http://nelsonsweb.net/wp-content/uploads/2011/09/p1.png"><img class="alignright size-medium wp-image-134" title="Template Explorer screen shot" src="http://nelsonsweb.net/wp-content/uploads/2011/09/p1-112x300.png" alt="" width="112" height="300" /></a>I have used several different methods for collecting SQL scripts (both that I have written, and have borrowed from others) to reuse.  A few that come to mind include: 1. saving the scripts in individual .sql files somewhere on my hard drive, 2. storing the scripts as an individual page in Microsoft Onenote. 3. saving scripts right in SSMS Template Explorer.</p>
<p>While I still have a collection of scripts in all 3 places for various purposes, I have been moving more and more towards using template explorer.<br />
The biggest reason for my change  is because whenever I need to run a script against a database server I am already opening up SSMS.  It is then easier to open up template explorer than it is to then click on File-&gt;Open, and then browse for a specific script.</p>
<h5>Lets get started</h5>
<ol>
<li>Open SSMS</li>
<li>Open the Template explorer by either using the key combination <span style="text-decoration: underline;"><strong>CTRL + ALT + T </strong></span> (my preferred method), or clicking on View-&gt;Template Explorer.</li>
<li>The template explorer will then open on the right hand dock in SSMS (kinda like how it shows up in my screen shot here!).</li>
</ol>
<p>From here you can expand any of the categories to see a list of applicable scripts.  Microsoft gives us a decent collection of templates to get us started and you can add your own scripts to the collection (covered in a future blog post).  Find a script template that you want to use and double click it.  SSMS will open that template up as a new query in the main window.  <strong><span style="color: #ff0000;">WARNING: Make sure that the script window is connected to the appropriate server\instance before executing any scripts.</span></strong> (not that I have ever done that&#8230;.)</p>
<p>For this example, I expanded the Backup category, and then double clicked on &#8220;Backup Database&#8221;</p>
<p><a href="http://nelsonsweb.net/wp-content/uploads/2011/09/p3.png"><img class="aligncenter size-full wp-image-138" title="backup database" src="http://nelsonsweb.net/wp-content/uploads/2011/09/p3.png" alt="" width="719" height="278" /></a></p>
<p>Now wait a minute, there&#8217;s a lot of funky stuff there.  &#8220;BACKUP DATABASE&#8221; won&#8217;t run.</p>
<p>Here comes the magic of Template Explorer.  Press <span style="text-decoration: underline;"><strong>CTRL + SHIFT + M</strong></span> on your keyboard.  Behold the Specify Values prompt box.</p>
<p><a href="http://nelsonsweb.net/wp-content/uploads/2011/09/p4.png"><img class="aligncenter size-full wp-image-139" title="select values" src="http://nelsonsweb.net/wp-content/uploads/2011/09/p4.png" alt="" width="437" height="311" /></a><br />
<a href="http://www.flickr.com/photos/hryckowian/17706394/"><img class="alignleft size-full wp-image-140" title="Magic!" src="http://nelsonsweb.net/wp-content/uploads/2011/09/17706394_f9b5968ba9_m.jpg" alt="" width="126" height="168" /></a>Fill in the database name, and the file location where you want the backup saved to and press OK.  Like Magic, the template place markers are removed from the script and replaced with the values that you specified a moment ago.  The script is now ready to run <strong><span style="color: #ff0000;">as long as you double check to make sure you are running it against the appropriate server\instance</span></strong>.</p>
<h5><span style="color: #ffffff;">.</span></h5>
<h5>A couple gotchas</h5>
<ul>
<li style="text-align: left;">All of the Template Explorer scripts are saved on my PC in:<br />
C:\Users\&lt;user profile&gt;\AppData\Roaming\Microsoft\Microsoft SQL Server\100\Tools\Shell\Templates\Sql<br />
This is running SSMS 2008 R2 on Windows 7.</li>
<li>This save path for the templates does not get backed up on my local PC.  It also does not travel if I use SSMS on another PC.</li>
<ul>
<li>So far my solution has been to use a Remote Desktop Connection back to my main work PC if I am using another PC in the office.</li>
<li>Every now and then I will manually copy the directory up to a network location that does get backed up so that I can get my templates back if my PC dies.  Does anyone have a better solution?</li>
</ul>
<li>If you delete a template or folder that Microsoft provided, it will be recreated whenever you restart SSMS.  I found that it is best to leave the Microsoft provided templates alone and add my own.</li>
</ul>
<p>Coming soon in a future post, making your own template. [EDIT: <a title="Creating a new template" href="http://nelsonsweb.net/2011/09/creating-a-new-template/">here is part 2</a>]</p>
<img src="http://feeds.feedburner.com/~r/Nelsonswebnet/~4/mrCZOu1S7i0" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://nelsonsweb.net/2011/09/ssms-template-explorer/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		<feedburner:origLink>http://nelsonsweb.net/2011/09/ssms-template-explorer/</feedburner:origLink></item>
	</channel>
</rss>

