Skip to main content

Posts

Showing posts from 2009

Retrieving SQL Error Messages - SQL Server 2005

Hi All! Hope you had a great summer! I was looking up the 'internets' for something and came across many people looking for a way to retrieve SQL Error Message based on an Error ID. Here's a quick solution - nothing outstanding; but good-to-know script! DECLARE @Error int DECLARE @ErrorMessage varchar(800) <... sql ...> <... sql ...> SET @Error = @@Error IF @Error <> 0 SET @ErrorMessage = isnull((select [text] from sys.messages where message_id = @Error),'Error. Details not found.') SELECT @Error as [Error ID], @ErrorMessage as [Error Message] GO Go Go Go. Execute. Regards! Please consider the environment before printing this blog! Go Green!

Off Topic - R.I.P. King Of Pop

Your music will be missed. Rest in Peace MJ. (Image Source: http://www.mediabistro.com/agencyspy/original/Michael_jackson_bad_cd_cover_1987_cdda.jpg)

Calculating Distance based on Lat/Long Coordinates

A friend of mine wrote this script for some reason and forwarded to me for the heck of it! I have no use for it but figured somebody else might be looking for it! So here it is... If you have any questions, feel free to post 'em and I will run it by Narayan. -- ============================== =============== -- Author: -- Create date: <24/04/2009> -- Description: -- ============================== =============== CREATE FUNCTION [dbo].[ udfLatLonRadiusDistance] ( @lat1Degrees decimal(15,12), @lon1Degrees decimal(15,12), @lat2Degrees decimal(15,12), @lon2Degrees decimal(15,12) ) RETURNS decimal(9,2) AS BEGIN DECLARE @ earthSphereRadiusNauticalMiles as decimal(10,6) DECLARE @ nauticalMileConversionToMilesF actor as decimal(7,6) SELECT @ earthSphereRadiusNauticalMiles = 6366.707019 SELECT @ nauticalMileConversionToMilesF actor = .621371 -- convert degrees to radians DECLARE @lat1Radians decimal(15,12) DECLARE @lon1Radians decimal(15,12) DECLARE @lat2Radians de

Alternating Row Background Color For SSRS Matrix (Pivot Table)

I had a tough time to apply alternate row colors to a SSRS Matrix and finally figured out! Without further ado, here it is... Assume you have a matrix with more than 1, lets say 2 row groupings; RG1 and RG2. 1. Right-click on RG2 (innermost row group), and select "Insert Group"; for simplicity call it "RowColorGroup" 2. In the "Group On" section, add some constant value - for example ="" or ="ankeet" etc... you get the idea! 3. Select the newly created group "RowColorGroup" and enter the following in its "Value" property: =iif(RunningValue(Fields!RG1.Value & Fields!RG2.Value,CountDistinct,Nothing) Mod 2, "LightSteelBlue", "White") 4. Select the "BackgroundColor" property of "RowColorGroup" and enter "=Value" 5. Set the width of "RowColorGroup" to 0pt and "CanGrow" to false 6. Select the data cell(s) and set their "BackgroundColor" pro

Search for text within all stored procedures

As simple as this process is, I have had many people ask me "How do I look for all stored procs that use a certain table or field?". Here's the simple answer: SELECT ROUTINE_NAME rn, ROUTINE_DEFINITION rd, * FROM INFORMATION_SCHEMA.ROUTINES WHERE ROUTINE_DEFINITION LIKE '%sstpay%' AND ROUTINE_TYPE='PROCEDURE' SELECT OBJECT_NAME(id) FROM syscomments WHERE [text] LIKE '%sstpay%' AND OBJECTPROPERTY(id, 'IsProcedure') = 1 GROUP BY OBJECT_NAME(id) Have Fun!