Wise man or Wise guy? You Decide

Just another WordPress.com weblog

Archive for the ‘SqlServerCentral’ Category

What happened to that email?

Posted by sqlwiseguy on September 10, 2009

This question:

Created script to send mails using sp_send_dbmail- working like a charm.
Now searching for a way to get result code of sent mail (like Success = Recipient got it,
Failure = Did not get regardless of the reason).
I mean SP return codes 0 (success) or 1 (failure) refer to correct mail Profile, not missing Recipient, etc.
Frankly not sure this is possible as it looks like outside Sql Server authority/responsibility?!

asked in this thread on SQLServerCentral prompted me to do some research into Database Mail.  The result of the research is that there is no way to get this information from SQL Server.

Basically the way Database Mail/sp_send_dbmail works is that the message is placed in a Service Broker queue (sp_send_dbmail returns success), the external Database Mail executable reads the queue and sends the message to the designated SMTP mail server.  If the mail server accepts the message then Database Mail is done and the status is set to sent.  So, if you have an incorrect email address or the receiving server refuses it, SQL Server has no way to know.  In order to find this out you would need to use a valid Reply To or From email address and monitor that mailbox.

Here’s the query I use for checking Database Mail:

msdb.dbo.sysmail_faileditems AS SF JOIN
msdb.dbo.sysmail_event_log AS SEL
ON SF.mailitem_id = SEL.mailitem_id

Let me know if you have any better ways to find errors for Database Mail.

Posted in Code, Database Mail, SQL Server, SqlServerCentral | Leave a Comment »

Types Matter!

Posted by sqlwiseguy on August 24, 2009

Louis Davidson (@DrSql) had an excellent series on his blog on the Pillars of Database Design and the one of the key elements of his first pillar A Cohesive Design is to for data types to make sense.  I couldn’t agree more.  I have seen more problems caused by using a character type to hold dates or numbers.  The developers, in each case I’m sure, decided that they would verify the type in the application, and I would bet they did.  What they didn’t do, was consider the case where a user get access via MS Access or some other tool and now can enter/modify data outside the application.  This is how you end up with Nobember 17 or February 30 as a date, 1O (yes that’s an letter o) or A17 as a number.  Now when it comes time to query those values or use them in a WHERE or JOIN, what are you going to do?  You will get conversion errors if you try to convert them to the proper data type.  Here’s a recent thread on SQLServerCentral where you can see many of the problems using a “generic” data type causes.
Look if the column is supposed to store dates use the appropriate DATE data type, most RDBMS products have a few, and if it is supposed to store numeric data use the proper NUMERIC data type.  So if you are storing a person’s age you don’t need BIGINT or DECIMAL, SMALLINT will work fine.  This is one of the things a database is designed to help with, verification that data is of the correct type, don’t keep the database engine from doing what it is designed to do!
Thanks for your suppport!

Posted in Best Practice, Development, Rants, SQL Server, SqlServerCentral | Leave a Comment »

No Training Budget Still No Excuse

Posted by sqlwiseguy on August 12, 2009

When I first started by career in IT and SQL Server about 10 years ago I lived in a small town in northern New Hampshire.  I used my location as an excuse not to attend user groups and other events, unless the boss was willing to foot the bill.  Now I realize my mistake, I’m in charge of my professional development, and now, location is no excuse.  Here’s a list of just some of the FREE training available online:

  • JumpstartTV – short (3-5 minute), specific how-to videos for SQL Server and .NET.
  • Channel 9 – MSDN’s video training library. This has videos on just about everything microsoft. Over 200 on SQL Server 2008 alone.
  • PASS – the Official Professional Association of SQL Server web site. PASS offers Virtual Chapters (user groups that meet online monthly).  Be sure to check out the upcoming 24 hours of PASS
  • Quest Software – Quest offers free webcasts on several technologies including SQL Server and some on Quest products but many general ones. Check out Quest Connect
  • SQLServerPedia – has video podcasts as well as blogs, wiki, and articles.
  • SQLServerCentral – forums, articles, scripts, blogs, and videos. What more can you ask for?

I’m sure there are other resources as well.

Now on to the FREE events. 

  • The biggest one for SQL Server, well, at least in my opinion, is the SQLSaturday franchise.  There have been about 20 over the last 2 years from Florida to Oregon.  I should make a disclaimer that I have spoken at 2, attended another, and the franchise is owned by my friend, Andy Warren and his partners.  Actually the first SQLSaturday event was when I met Andy, actually the day before at the Day with Celko event done in conjunction with the SQLSaturday.  It’s a full day of free SQL Server training with some national speakers along with the best local speakers.
  • Code Camps – these one day events for .NET are what SQLSaturday is based on, so if you need .NET training here’s a way to get it.
  • PASS – offers a SQLSaturday like event support with it’s Community Connections
  • User Groups – just BING or GOOGLE for [your technology and location] User Group.  I’m sure you’ll find something in your area.  PASS has a list of official chapters for SQL Server.  I know of Sharepoint, Java, .NET, and Agile user groups.  I’m sure there are others.

As you can see there are plenty of training options that will only cost you time and maybe travel expenses and that’s really an investment in you. 

Posted in Community, JumpstartTV, PASS, Professional Development, SQL Server, SQLSaturday, SqlServerCentral, Training, User Group | 4 Comments »

Article re-featured on SQLServerCentral

Posted by sqlwiseguy on July 31, 2009

The second article I had published on SQLServerCentral, ANSI PADDING, Trailing Whitespace, and Variable Length Character Columns, was re-featured in the newsletter and on the home page today. 

My favorite part of being published is the discussion that hopefully follows.  Even if there are some negative comments, I just consider that an extension of the learning environment.

Posted in Professional Development, Published Articles, SQL Server, SqlServerCentral | Leave a Comment »

Learning some javascript

Posted by sqlwiseguy on July 24, 2009

As part of my work I need to be a “Jack of all trades” meaning I not only need to be able to do SQL Server DBA and development tasks, but I also need to be capable of doing .NET and VFP development.  Yes, I did say VFP (Visual FoxPro for those who are too young to know what it is). 

The major project in which I am involved is using SQL Server and ASP.NET (C#) MVC.  Fortunately I had downloaded Scott Guthrie’s NerdDinner tutorial when it first came out and have just finished going through it.  In the tutorial I came across some code like this:

if (item.Description !== undefined) {
description = item.Description;

Well, I had never seen the !== operator before and assumed that it was a typo and was supposed to be:

if (item.Description != undefined) {
description = item.Description;

since I know that == the equality comparison operator and != is the inequality comparison operator.  Well, then I found the same operator later in the code, so I thought, “Hmmm, maybe this isn’t a typo, but a real operator?”, so off to www.google-vs-bing.com to see what I could find.  Well, I didn’t find anything helpful on page 1 of either search engine’s results.  Next a quick question on Twitter.  Ahhh, several replies that, “Yes !== and === are operators and they compare type AND value”.  Having always programmed in strongly typed languages this is new and interesting to me.  So basically in javascript 1 == “1” is true, but 1 === “1” is false.

I still would rather be in SQL, but at least now I am starting to understand more about javascript.

Posted in Development, Professional Development, Programming, SqlServerCentral | 1 Comment »

Introduction to Profiler published on SQLServerCentral

Posted by sqlwiseguy on April 15, 2009

My article Introduction to Profiler has been published on SQLServerCentral today.  This is part of one of a series that I am working on and covers the basics of Profiler.  The rest of the series will build to more complex uses of Profiler.

Posted in Community, Professional Development, Profiler, Published Articles, SQL Server, SqlServerCentral | 2 Comments »

The Deception of IsNumeric()

Posted by sqlwiseguy on April 14, 2009

Has anyone else ever used the IsNumeric() function to try to eliminate this error (or similar):

Msg 8114, Level 16, State 5, Line 1
Error converting data type varchar to numeric.

yet still get the error? Isn’t that what the function is for?  Here’s what is says in BOL:

ISNUMERIC returns 1 when the input expression evaluates to a valid numeric data type; otherwise it returns 0

But run this code (generates a list of ASCII Characters):

;WITH cteNumbers AS
sys.all_columns AS AC
n AS ASCII_code,
CHAR(n) AS [character],
ISNUMERIC(CHAR(n)) AS is_numeric
n <=255 AND

And you’ll see that the first 10 rows and last 8 rows returned are not what I would consider numeric.  Or how about this:

CONVERT(DECIMAL(9,2), '20,00')

The first statement returns 1, while the second fails. 

Here is the last interesting behavior of IsNumeric() in relation to Cast/Convert provided by Frank Kalis on this SQLServerCentral thread:


E           F          
----------- -----------
0           0

(1 row(s) affected)



E           F          
----------- -----------
14          15

The moral of the story is that IsNumeric() <> CanBeConvertedToNumeric().

So what is the answer?  I don’t know.  You would need to customize the solution to meet your specific situation.  Jeff Moden suggests an IsAllDigits function in this thread on SQLServerCentral for instances where you want to eliminate rows with non-numeric characters.

Do you have anything that you recommend?

Posted in Bugs, Code, Code Example, Problems, SQL Server, SqlServerCentral | Leave a Comment »

Deploying Custom SSIS Components

Posted by sqlwiseguy on April 9, 2009

This post is really for me.  I have written 1 custom component for SSIS 2005 and wrote an article on it for SQLServerCentral that was recently re-published.  In the discussion someone asked for specific steps for installing and using it.  Well, since it has been about a year, I couldn’t remember all the specifics so I’m blogging the steps so I have place to go the next time I need it.  So on with the steps:

  1. Register the component in the GAC (Global Assembly Cache).  There are 2 ways to this:
    • Drag and drop the component into C:\Windows\Assembly
    • Use the GAC utility that that is part of the Visual Studio SDK and the Windows SDK.  Here is the syntax:
        gacutil.exe  /if Path\AssemblyName
    • Depending on which one you installed it will be located in one (or both) of these locations if you used the default install:
      • C:\Program Files\Microsoft Visual Studio 8\SDK\v2.0\Bin
      • C:\Program Files\Microsoft SDKs\Windows\v6.0\Bin
  2. On your development machine put the component in one of the folders under C:\Program Files\Microsoft SQL Server\90\DTS (default install location):
    • \Connections
    • \ForEachEnumerators
    • \LogProviders
    • \PipelineComponents
    • \Tasks

The component I created is a Pipeline Component so it belongs in the PiplelineComponents folder.  Once you have put it here you can add it to your toolbox by right-clicking on the toolbox, selecting “Choose Items”, select the SSIS Data Flow Items tab (in this case), and select the Error Details component.

This is really a summarization of this blog post by Matthew Roche that you can read for more details.

Posted in Development, Personal, Published Articles, SQL Server, SqlServerCentral, SSIS, Tools | Leave a Comment »

Error Handling in SSIS re-featured on SQLServerCentral

Posted by sqlwiseguy on April 3, 2009

I am honored that my first ever published article, Error Handling in SSIS, was re-featured on SQLServerCentral today.  I don’t know how Steve selects articles to feature a second time, but I assume it was because they were popular.  Here are a couple of earlier blog posts about this article/subject:

Error Handling in SSIS Published

SSIS Error Logging Custom Component

Posted in Development, Professional Development, Programming, SQL Server, SqlServerCentral, SSIS | Leave a Comment »

Update on my 2009 Goals

Posted by sqlwiseguy on April 2, 2009

Since we are 1/4 through the year I thought I should give an update on my goals.  Overall I think I am doing okay, but I need to work toward them with more purpose.

  1. Learn SQL Server 2008, particularly policy-based management, resource governor, and service broker.
      Not a whole lot of progress here.  I do have it installed on my laptop, but I have not done much with it, nor have I bought any books.  I really need to get started.
  2. Write 1 Article per quarter for SQLServerCentral.
      Well, I did get an article submitted in the first quarter which will be posted early in the second quarter so I am on target, especially since I have the information for at least 2 more articles already, so I “just” need to write them.
  3. Record and submit 1 video per quarter for JumpstartTV
      Again I did get one done in the first quarter so I am on target.  I also have some ideas for others so it is all about getting them scripted and recorded.
  4. One Blog post per week
      Another one I am meeting with 19 posts in the first quarter.  I have to admit to this being a struggle for me.  I really want the posts to have good content and not just be announcements and recaps of meetings I have been to.  There is nothing wrong with those posts, but I’d like to be sharing something others can learn from more often.  I think that as I write more, it will get easier and better, not just to write, but also to find topics.
  5. Become more involved in leadership in my local user group (OPASS).
      I’m trying to do make the time to do this, but I need to be more purposeful about it.  I am trying to help out by pursuing speakers from within my network.  Of course, a bigger network would make it easier.  Time is limited and whatever I do try to do I want to do well.  Also I have become more involved in PASS as my friend Andy Warren (the OPASS president) is on the board of directors, so I’m trying to help out there as well.
  6. Speak at 2 community events.
      I have a submitted a session to SQLSaturday – Pensacola and will be submitting at least one session for the PASS Summit, so I am making some effort.  I do need to contact some of the other User Groups within driving distance (Tampa, Jacksonville) so I can get more experience.  Odds are I will put together another presentation for OPASS this year and at the next SQLSaturday – Orlando.
  7. Attend the PASS Summit
      I am working on this one.  I have spoken to my boss about possibly getting some funds for it, but, regardless, I plan on going.  As I already mentioned I will also be submitting at least one session.  This is probably the easiest one to do as all it takes is a little money and some vacation time.

Posted in Community, Goals, JumpstartTV, OPASS, PASS, Professional Development, Speaking, SQL Server, SQLSaturday, SqlServerCentral, User Group, Volunteering | Leave a Comment »