SQL

Packt Publishing Thousand Titles Campaign–free eBook!

Packt Publishing is celebrating the release of its 1000th title by offering web site members their choice of free eBook. They are also opening their online library for a week for free to members, to allow you to research your choice. 

If you’re not already a member, signing up is free, but you have to do so by September 30th to get the free eBook.

To sign up, just go to www.packtpub.com/login.

Validating NPI (National Provider Identifier) numbers in SQL

If you work with any kind of healthcare data, then odds are you’ll deal with NPI (National Provider Identifier) numbers. The NPI is a 10-digit number consisting of 9 digits (with the first digit being a 1 or a 2) followed by a check digit. The check digit uses the Luhn algorithm, which is calculated like this: Double the value of alternate digits beginning with the rightmost digit. Add the individual digits of the products resulting from step 1 to the unaffected digits from the original number. Subtract ......

Calculate distance between two latitude/longitude points in SQL

I'm working on a mobile location search app, and needed a way to find addresses within a certain radius of the device's current position. A little Googling found a simple function that will return the distance in miles: CREATE FUNCTION dbo.Distance( @lat1 float , @long1 float , @lat2 float , @long2 float) RETURNS float AS BEGIN DECLARE @DegToRad float = 57.29577951 DECLARE @Ans float = 0 DECLARE @Miles float = 0 SET @Ans = SIN(@lat1 / @DegToRad) * SIN(@lat2 / @DegToRad) + COS(@lat1 / @DegToRad ) ......

Review: Redgate SQL Source Control

RedGate SQL Source Control is a Management Studio add-in that allows you to seamlessly (hopefully...) connect your existing source control system to SQL Server. It is advertised as doing all the typical stuff you'd expect: Source control schemas and data within SSMS Connect databases to TFS, SVN, Sourcegear Vault, Vault Pro, Mercurial, Perforce, Git, Bazaar, and any source control system with a capable command line Work with shared development databases, or individual copies Track changes to follow ......

Getting SQL table row counts via sysindexes vs. sys.indexes

Among the many useful SQL snippets I regularly use is this little bit that will return row counts in a table: SELECT so.name as TableName, MAX(si.rows) as [RowCount] FROM sysobjects so JOIN sysindexes si ON si.id = OBJECT_ID(so.name) WHERE so.xtype = 'U' GROUP BY so.name ORDER BY [RowCount] DESC This is handy to find tables that have grown wildly, zero-row tables that could (possibly) be dropped, or other clues into the data. Right off the bat you may spot some "non-ideal" code - I'm using sysobjects ......

Dallas GiveCamp - developing for non-profit organizations

GiveCamp is a weekend-long event where software developers, designers, and database administrators donate their time to create custom software for non-profit organizations. This custom software could be a new website for the nonprofit organization, a small data-collection application to keep track of members, or a application for the Red Cross that automatically emails a blood donor three months after they’ve donated blood to remind them that they are now eligible to donate again. The only limitation ......

SQL Server error: Invoke or BeginInvoke cannot be called on a control until the window handle has been created

I needed to downgrade SQL Server 2008 from Enterprise to Standard on a Server 2008 machine, and and kept getting this error when trying to uninstall: SQL Server Setup has encountered the following error: Invoke or BeginInvoke cannot be called on a control until the window handle has been created It turns out the setup utility really doesn't like having ANY other windows open - I closed the Server Manager window and it worked ......