SQL313
  • Home
  • Blog
  • License
  • Downloads

Add Location to Open File dialog window in SSMS

Details
Written by: Glenda Gable
Category: SSMS
Published: 07 May 2013

Recently I realized I kept going to the same folder over and over...  I have my "play" files on my C:\ drive, but I have a network share that I keep scripts and project related stuff that I really dont want to lose.  Most of my stuff is database development related, so the stuff on my C:\ drive is also in the DEV database (and I am lucky enough to be the main one who works in DEV - only 2 others really do and that is minimally).

I put a shortcut in the My Documents folder, but realized that it didnt help as much as I wanted.  Therefore, I found a way of putting a shortcut in the left hand pane of the Open dialog box. Look at the "home" option in the image below - that is custom :)

Read more: Add Location to Open File dialog window in SSMS

Oracle datetimestamp to SQL Server datetime

Details
Written by: Glenda Gable
Category: T-SQL
Published: 03 May 2013

Why doesnt this work Arggg... I am a SQL Server worker... why do I need to know Oracle too??? That is what I thought when I came across a situtation where dates were throwing a fit. I was pulling data from Oracle into a SQL database.

I started using the LINKED SERVER, but switched to use OPENQUERY because they work differently. At first I didnt care why they did, but I am now coming back to learn much more about it and explain it. Honestly, I am hoping I will remember I am typing this so that when it comes up again, I will have a place to check! :)

This article is all about the dates, not about other data types (hence the name). I learned an interesting fact: SQL Server allows dates to go back to January 1, 1753, but Oracle allows dates earlier than that.

The problem was the date I was trying to bring into SQL was before that date and therefore threw an error:

Msg 8114, Level 16, State 8, Line 4 
Error converting data type DBTYPE_DBTIMESTAMP to datetime.

OPENQUERY sends the query to the remove server to be executed there, rather than being executed on the server calling the query, which is what a LINKED SERVER does. To make myself remember it better, using the LINKED SERVER gets back all raw data from Oracle, then processes the query more, which means the dates we want are included and therefore throws an error. On the other hand, using OPENQUERY makes the Oracle database process the query, which means the dates are not included in the returned recordset. It also means that with OPENQUERY we can use the Oracle functions, which is very handy at times.

Read more: Oracle datetimestamp to SQL Server datetime

Word Wrap in Annotations

Details
Written by: Glenda Gable
Category: SSIS
Published: 27 December 2012

Well - one would think that word wrap would be something that isnt too difficult, but when I started typing in an annotation today (look at me - commenting!!), it didnt wrap my text.  I tried enter, to no avail.  If you are stuck - hit Ctrl-Enter and that will wrap your text for you.  Simple enough, but it took me a little bit to find it.  Hope it helps someone! :)

Oh where, Oh where ... has my column gone?

Details
Written by: ggable313
Category: SSIS
Published: 11 September 2012

Phew - I ran into something I knew would be soooo simple, but couldnt figure it out!  Don't you hate that?  Luckily a co-worker helped plug away at it and wham-o we found it!

I had a derived column with a little bit of logic, but not much, then added a data viewer after it to see the results.  Then, added another column within the derived column step.  When I went to look at the results in the data viewer - my column was no where to be found!  Ohh my!!

Turns out, when you create a data viewer it takes the columns it gets, and if you add another upstream, it wont reflect that change.  To change this, you go to the Data Flow Path Editor and click on the "Configure..." button in the bottom right corner (SSIS 2008 R2).  When you bring up the configuration dialog window, you will see a list of columns.  More than likely your new column is in the left hand box - move it to the right and presto! - you can now view that data to your heart's content!  What my co-worker pointed out was that you can also remove the extraneous columns you dont care to look at when you are using the data viewer.

Hope this helps someone find that missing column! :)

Using Transactions

Details
Written by: Glenda Gable
Category: T-SQL
Published: 05 September 2012

I wanted to jot some notes down about using transactions and @@trancount - mostly, I personally like checking for if I should begin a transaction or not at the beginning of stored procedures.  I know this comes from me being a software developer and thinking the database guy/gal handles all that, and then learning more about the database side of things and realizing database coding isnt always reviewed that closely by a DBA.  So, it came time for me to learn.  Now that I switched jobs, I dont have all the code blocks to copy/paste - so this blog post will help with that! :)

Lets start with the basics:

A transaction is a sequence of operations performed in it's own "bubble" from other processes and/or transactions occuring.  Once a transaction is completed, the effects are permanent in the database.

Now, that is a simple explanation, as with everything, there are many things that go into it - such as how transactions affect each other because the data that is modified in 1 transaction is the same data needed for another transaction, so the "bubble" a transaction is in isnt completely isolated - or how if a transaction is rolled back, there is no permanent effect because nothing was done, etc.  I am going to talk about some of the ways of starting, monitoring, and ending a transaction, as well as nested transactions, and possibly uncommitable transactions.

To start a transaction, the syntax is BEGIN TRANSACTION (or BEGIN TRAN).  No matter what, this is pretty much straight forward.  To end a transaction, you would either use COMMIT TRANSACTION, or ROLLBACK TRANSACTION, depending on if you want to make the changes you made, or not make the desired changes, respectively.  That, in and of itself, is all you need to start utilizing transactions now - but I will keep going with more juicy info. :)

Read more: Using Transactions

T-SQL Random Number Generator

Details
Written by: Glenda Gable
Category: T-SQL
Published: 31 August 2012

I recently needed to generate a random number.  I know using rand() was the way to go, but it wsnt giving me the formatting I needed.  I went online (lazy, cause I know I could format a stupid number) and found an amazing little script that I expanded upon.  It gives you a min and max range which was perfect!

Here is the code and a link to the site I got it from (giving props to Michelle at sqlfool.com for it!)

Declare @maxRandomValue tinyint = 100
	, @minRandomValue tinyint = 0;
 
Select Cast(((@maxRandomValue + 1) - @minRandomValue) 
	* Rand() + @minRandomValue As tinyint) As 'randomNumber';

http://sqlfool.com/2009/06/random-number-generator-in-tsql/

T-SQL and XML

Details
Written by: Glenda Gable
Category: T-SQL
Published: 23 August 2012

I was wary of XML when I first heard about it - mostly because I was still trying to wrap my head around other stuff that I was learning.  Therefore, I didnt learn much about it at first.  Then, I needed to pass multiple values to a stored procedure and looked into it.  I quickly fell in love!!  There are many posts about using XML within T-SQL.  I am posting one so that I can search on my own blog for this when I need it - I dont seem to keep it in my head long enough to use it the next time I need it. :)

I am going to use examples from my alerter system, that is where I am using it as I am writing this article - so 2 birds with 1 stone - cant beat that!  By the way, I will format the SQL code better - it looks weird being all gray!

Read more: T-SQL and XML

  • 1
  • 2
  • 3
  • 4
  • 5

Common Tags

  • tsqltues 7
  • ssis 7
  • tsql 4
  • presentation 3
  • career growth 3
  • file 3
  • xml 2
  • downloads 2
  • indexes 2
  • performance 2
  • oracle 2
  • dbafun 1
  • personal growth 1
  • processes 1
  • ssms 1
  • project 1
  • businessintelligence 1
  • cursor 1
  • etl 1
  • datawarehouse 1

Blog

  • T-SQL Tuesday #112
  • 2018 - A much needed Kick in the Rump

ggable@sql313.com

LinkedIn