SQLXML: Fun with SQLXML XQuery – Miscellaneous Functions – Part 1

Just going through some old notes; here are some samples I compiled before that might still be of interest to those of you who are venturing into SQLXML.

The samples below are using miscellaneous numeric and string functions.

Have fun!

Sample XML

SELECT @xml = ‘
<Employees Dept=”IT”>
<Employee Number=”1001″ Hourly=”11.35″ FullName=”Suzy Jacobs”>
<Employee Number=”10″ FullName=”Bob Willow” ReportsTo=”Steve Wong”/>
<Employee Number=”1003″ FullName=”Tony Carpenter” FName=”Tony” LName=”Carpenter”/>
<Employee Number=”1004″ FullName=”Suzy Jacobs” FName=”Suzy” LName=”Jacobs”/>
<Staff Number=”1003″ FName=”John” FullName=”John Smith” LName=”Smith” Department=”ABC” />
<MoreStaff Number=”1020″ FullName=”Ronnie Bates” FName=”Ronnie” LName=”Bates” Address=”XYZ” Department=”ABC” />

Continue reading

Understanding SQL Server Statistics

Originally posted on Idera – http://sqlserverperformance.idera.com/tsql-optimization/understanding-sql-server-statistics/

“Statistics provides tools that you need in order to react intelligently to information you hear or read” – David Lane, 2003

If there’s an upcoming election and you are running for office and getting ready to go from town to town city to city with your flyers, you will want to know approximately how many flyers you’re going to bring.

If you’re the coach of a sports team, you will want to know your players’ stats before you decide who to play when, and against who. You will often play a matchup game, even if you have 20 players, you might be allowed to play just 5 at a time, and you will want to know which of your players will best match up to the other team’s roster. And you don’t want to interview them one by one at game time (table scan), you want to know, based on their statistics, who your best bets are.

Just like the election candidate or the sports coach, SQL Server tries to use statistics to “react intelligently” in its query optimization. Knowing number of records, density of pages, histogram, or available indexes help the SQL Server optimizer “guess” more accurately how it can best retrieve data. A common misnomer is that if you have indexes, SQL Server will use those indexes to retrieve records in your query. Not necessarily. If you create, let’s say, an index to a column City and <90% of the values are ‘Vancouver’, SQL Server will most likely opt for a table scan instead of using the index if it knows these stats.

Continue reading

Troubleshooting Replication Error: A required privilege is not held by the client

Troubleshooting Replication Error: A required privilege is not held by the client

If you ever you encounter this replication issue, the resolution might be fairly simple, however it will require that you toggle your SQL Service accounts.

Have a look at this KB:

The KB suggests the service account might have changed using a tool other than the Configuration Manager (technically a no-no because the SSCM, in addition to changing the service accounts, also performs updates to associated settings like windows registry entries). Try toggling the service accounts in Configuration Manager (for ex, from Administrator, to something Local, to administrator again) and that should flush the old credentials.

Continue reading

@msshushu’s and @sqlbelle’s take on “Why BCIT”?

Shereen (blog | @msshushu) and I are going to participate tonight at BCIT’s Info Session for the School of Computing.

Shereen and I are both true blue BCIT alumni. We both have our CST Diplomas from BCIT, and both pursued our degrees at BCIT.

There are a lot of reasons why we went to BCIT, and why going to BCIT worked for us.
Here’s our take on “Why BCIT?”


Invalid Credentials Error During SQL Server 2008/R2 Install

In case you get the following errors:

The credentials you provided for the SQL Server Agent service are invalid. To continue, provide a valid account and password for the SQL Server Agent service.

The specified credentials for the SQL Server service are not valid. To continue, provide a valid account and password for the SQL Server service.

Here’s the simple solution:

Meme Monday – SQL Server Story in 11 Words or Less

I’ve been tagged by the awesome tweep/blogger, Janice C Lee (blog | twitter) for Tom LaRock’s (blog | twitter) Meme Monday (Write a SQL blog post that tells a story in 11 words or less).

Here’s my 11-words-or-less-sql-story:

It’s fun working with SQL Server. Sometimes stressful, but always fun.

Now I want to tag another 3 awesome tweeps/bloggers:

Wendy Pastrick (blog | twitter)
Michelle Ufford (blog | twitter)
Kendra Litte (blog | twitter)

Happy Monday everyone!