Wednesday, June 24, 2009

You Can't Copyright Common Sense

No you cannot, unless your name happens to be Thomas Payne, you were born over 200 years ago, and actually published the pamphlet titled, "Common Sense".

The truth is that if you listen to most speakers today or read one of the plethora of books about sales, service or whatever, you will find that they are telling you about what you probably already know. For example, "A firm handshake and friendly smile go a long way toward making a lasting impression".... well of course it does.

Is there any true new ground when it comes to human interaction that has not already been written? Possibly, but not nearly as much as has been re-written over and again since the beginning of recorded time. So the question is, why do people keep buying the books, listening to those speakers or receiving the epiphanies in the middle of the night?

The answer is simple. No you cannot copyright common sense - but what ideas you put together behind what you say is as important as how you put your personal brand on it.

Wednesday, June 10, 2009

Dynamic SQL Passthrough Queries with Parameters

If you need to run a passthrough query against another DBMS and need to create that SQL on the fly because of a parameter, then you may be out of luck. At least, according to MSDN:
http://msdn.microsoft.com/en-us/library/ms188427.aspx

However, there is a nice workaround you can employ that will do the job. Here is an example:

-- variable to contain the passthrough sql statement
DECLARE @SQL VARCHAR(300)
-- variable to contain the dynamic lookup value into the query
DECLARE @KeyLookup INTEGER
-- varliable to contain the passthrough query
DECLARE @query VARCHAR(400)
-- populate the keylookup value
SET @KeyLookup = 102
-- prepare the sql statment for the passthrough query
SET @query = 'select * from some_table where key_value = ' + CONVERT(VARCHAR(10) , @KeyLookup)
-- prepare the passthrough execution query
SET @sql = 'select * from openquery(linkedservername, ''' + @query + ''')'
-- option to print the passthrough execution query in full for debug purposes (this is nice because you can paste it into a sql

-- editor and run it to see what is wrong)
PRINT @SQL
-- execute the passthrough
EXEC (@SQL)

Monday, June 1, 2009

Creating System Stored Procedures

So what are the steps to creating a systemwide stored procedure in SQL Server?
  • Create them in the Master Database
  • Name must start with "sp_"
  • Mark them as System Objects using
    • for sql 2000 - master.dbo.sp_MS_upd_sysobj_category
    • For 2005 and later - sys.sp_MS_marksystemobject
For a test in 2008:
  1. Create a stored procedure in the system databaseone called sp_test
  2. Register them as system stored procs using sp_MS_marksystemobject.
  3. Then try to use them each from another database without prefixing them with master.dbo.