wetmatter nonsense

let's get random 
Filed under

sql

 

SQL Saturday Phoenix (Help Wanted)

As you may have heard SQL Saturday Phoenix is underway. We are aiming for an end of July time frame and are in need of the community's involvement. We need presenters, sponsors and volunteers. All is open to suggestions so please, PLEASE voice your opinion and participate. 

If you are interested in supporting SQL Saturday Phoenix please signup using the appropriate form below. Please pass this information on.

Loading mentions Retweet
Filed under  //   community   database professionals   free sql training   free training   knowledge sharing   multiple sessions   networking   one day event   phoenix   social networking   sql   sql community   sql saturday   sql server   sql server community    two tracks  
Posted by Samson Loo 

Comments [0]

Creating a Database Snapshot

This is a quick vid that steps you through the process of creating a database snapshot, restoring a database from a snapshot and dropping a snapshot. I typically use snapshot while I am in a testing mode. I quickly create a snapshot and make all my modifications, run through my test and blow it all away by restoring from my recent snapshot. It is very useful and I use it often on my local development instances. Hopefully you will find it just as useful.

Loading mentions Retweet
Filed under  //   create   creating a snapshot   database snapshots   drop   restore   sql   sql server  
Posted by Samson Loo 

Comments [0]

SQL Saturday Phoenix?

Is SQL Saturday really coming to Phoenix? Well the announcement was made public at the Arizona PASS chapter in a recent user group meeting. It is currently being lead by @Hafthor, @Coneybeer and myself @sqlsamson. We have teamed up and are looking to get the community involved! If you don't know what SQL Saturday is then allow me to brief you on it. It is a one day FREE training event that is conveniently held on a Saturday. In these troubled times FREE training never sounded so good! How great is that? SQL Saturday offers two tracks with four to six sessions for each track lasting about an hour each. The best part is that the speakers are fellow SQL Server enthusiast from our very own local community. You know them and you love them so come out and show your support!

If you are familiar with SQL Saturday then you know it was picked up by (PASS) the Professional Association of SQL Server not long ago and the fact it is in its planning stages here in Arizona is exciting. With such a large and overwhelming amount of knowledge sharing that SQL Saturday has to offer, it will be to valuable asset to the community. Keep in mind that SQL Saturday won't be a success unless you get involved. We need support from the community in several different areas. If you are apart of another technical group please spread the word that SQL Saturday is coming and we are looking for speakers/presenters, sponsors, volunteers, and of course venues.

If you are willing to present, sponsor, volunteer or can assist with getting locations please contact either one of the following:

For more information about SQL Saturday please visit SQLSaturday.com. I hope to hear from you and more importantly I hope to see you there!!!!

For information about the Arizona PASS chapter please visit Arizona PASS

-- samson

Loading mentions Retweet
Filed under  //   community   database professionals   free sql training   free training   knowledge sharing   multiple sessions   networking   one day event   phoenix   sql   sql community   sql saturday   sql server community    two tracks  
Posted by Samson Loo 

Comments [0]

Installing SQL Server 2000

This video steps you through the installation process of installing
SQL Server 2000 very quickly and very straightforward. This video is
one part of a series that goes through the upgrade process from 2000
to 2005 and on to 2008.

Loading mentions Retweet
Filed under  //   developer edition   gui setup   installation   sql   sql server 2000   sql server  
Posted by Samson Loo 

Comments [0]

sqlshots: Installing SQL Server 2008 via Configuration File

Loading mentions Retweet
Filed under  //   configuration file   installation   sql   sql server   sql server 2008   sql server 2008 express   unattended install with configuration file  
Posted by Samson Loo 

Comments [0]

sqlshots: Extracting Installation Files from SQL Server 2008 Express Install Package

Loading mentions Retweet
Filed under  //   extract install files   sql   sql server   sql server 2008   sql server 2008 express  
Posted by Samson Loo 

Comments [0]

sqlshots: Working with a Suspect Database

Recently I faced a problem with a mobile device (subscriber) which had a suspect database. I tried running the following command to check the database:

 DBCC CHECKDB ('databasename') 

but it did not work. I wanted to try a few other options, but the need for the device out weighed pin pointing the root problem. So I had to reinitialize the device and send it on it's way.  In the meantime I research a bit and ended up talking with a fellow DBA by the name of David Underwood (LinkedIn Profile). The good guy provided some very useful links which illustrated some measures to take. Here is the Code Project Link: http://bit.ly/72ar6x

The Code Project Site basically states to use the following statements.

 EXEC sp_resetstatus 'yourDBname';
 ALTER DATABASE yourDBname SET EMERGENCY
 DBCC checkdb('yourDBname')
 ALTER DATABASE yourDBname SET SINGLE_USER WITH ROLLBACK IMMEDIATE
 DBCC CheckDB ('yourDBname', REPAIR_ALLOW_DATA_LOSS)
 ALTER DATABASE yourDBname SET MULTI_USER 

If I get the opportunity I will certainly attempt it.  Since I was not working on the actual device I had to look for another route.

So I decided (since I had to expedite my troubleshooting efforts and get the device back in the rotation ASAP) to stop the SQL service and copy the actual problematic database files from the data directory. With the files in reach I felt that I could attach them to a Virtual Instance and troubleshoot the problem further. So here are the steps I took.

1. Opened up SQL Server Management Studio (SSMS)

2. Right clicked on the SQL Instance and selected Attach

3. Click the Add button

4. Select the database file

5. Clicked Ok

6. Received the Attachment Error

7. Click on the Hyperlink to see the Details

8. Decided I should remove the LOG file

9. Removed the physical LDF file from the Data directory (I had a backup of both)

10. Clicked Ok

11. The Database attached fine

I wonder if I had taken the same approach would it have resolved my issue?  I guess I'll never know until it happens again. Who am I kidding... you can't!

 

Loading mentions Retweet
Filed under  //   attach database   dbcc   dbcc checkdb   sql   sqlshots   suspect   suspect database   tsql  
Posted by Samson Loo 

Comments [0]

sqlshots: Add Leading Zeros

Typically in most cases you find yourself removing leading zeros but in this case I needed to add leading zeros to a column. 

Remove Leading Zeros

 SELECT CAST(CAST(ColumnName AS INT) AS VARCHAR(10)) FROM TableName

Let's Pad the field

Since I needed 6 chars this will add 3 spaces to the front of the numbers

 SELECT STR(ColumnName, 6) FROM TableName 

Add Leading Zeros

Let's say we need to add zeros to an employee id, well this would be an easy way to accomplish it. First we pad it with spaces and replace those spaces with zeros.

 SELECT REPLACE(STR(ColumnName, 6), SPACE(1), '0') FROM TableName 



SELECT SalesPersonID 
       ,REPLACE(STR(SalesPersonID, 6), SPACE(1), '0') AS PaddedSalesPID  
FROM   Sales.SalesPerson


Note: the SPACE(1) is equivalent to ' ' (That is a Tick Space Tick) So two Ticks with a space in between)

Update Table



UPDATE Sales.SalesPerson 
SET newSalesPID = REPLACE(STR(SalesPersonID, 6), SPACE(1), '0')


Loading mentions Retweet
Filed under  //   add leading zeros   sql   sqlshots   t-sql   transact-sql  
Posted by Samson Loo 

Comments [0]

sqlshots: Querying tables without a (JOIN CLAUSE)

Typically you would use a JOIN clause when querying from multiple tables, but no one said you have to. Say for example you wanted to query two tables (tableA & tableB) which did not have any relationship (no one-to-one at all), yet there are fields in which would permit a comparison. Say street number, pre-direction, street name and the suffix.

Well you would compare
(tableA.street number = tableB.street number) and
(tableA.pre-direction = tableB.pre-direction) and
(tableA.street name = tableB.street name) and
(tableA.suffix = tableB.suffix).

Well I did not have a sample dataset for that illustration but I do have the AdventureWorks database, so here we go.

This first example will illustrate a query using a JOIN clause.

Results

This example illustrates a query without using a JOIN clause.

NOJOIN_Query

Results

As you can see the results are the same, but the queries are a tad different.

-- samson

 

Loading mentions Retweet
Filed under  //   inner join   join clause   joinless queries   quering multiple tables without using a join clause   sql   sqlshots   ssms   tsql  
Posted by Samson Loo 

Comments [0]

sqlshots: SELECT-TRIM-CASE-CONCAT

In this particular scenario I needed to concatenate a set of fields into a single column. So essentially I needed to trim all the leading zeros from the street number field first (via my udf_TrimLeadingZeros), then pieced the street number, pre-direction, street name and suffix all into one field. However, every row did not have a pre-direction or a suffix; nonetheless, I needed everything formatted (evenly spaced between words) and displayed as a single string.

So I figured I would use a CASE expression (http://bit.ly/PiYQF) in conjunction with a String Concatenation (http://bit.ly/FJtq9) to achieve my end result. Typically I see a period (.) appended to the pre-direction, but in this case it wasn't required. However if you do need it simply add a period to line 14 between the ticks '. ' of the attached select script (see pre-direction with periods screen shot for details).

Pre-Direction without periods

Pre-Direction with periods

Click here to download:
CREATE.udf_TrimLeadingZeros_v0.01.sql (0 KB)

Click here to download:
SELECT.Trim-Case-ConCat_v0.01.sql (0 KB)

Loading mentions Retweet
Filed under  //   case   case expressions   select   select case   sql   sql server 2005   sql server management studio   ssms   string concatenation   tsql  
Posted by Samson Loo 

Comments [0]