Consider the following:
DECLARE @I int;
DECLARE @B bit;
DECLARE @False bit;
DECLARE @True bit;
SET @False = 'false';
SET @True = 'true';
SET @I = -5;
--this much we pretty much expect
select @False, @True
-- but what about this ?
WHILE @I < 5
BEGIN
SET @B = @I;
SELECT @I
, @b;
SET @I = @I + 1;
END
While the BIT datatype will throw errors
Practical Business Intelligence Solutions using the
Microsoft BI Suite of Tools provided along with Microsoft SQL Server
Showing posts with label sql 2008. Show all posts
Showing posts with label sql 2008. Show all posts
Monday, July 30, 2012
Jumbled Unreadable SSRS Report Details
In developing reports which have many columns, you may find that the detail lines become jumbled up and unreadable. Note that the column headers are just fine though.
To save time and headache with your reports, always select your detail line(s) withing the IDE and be sure that the background color is not set to "clear". In fact, giving them each a color is a good idea. Note also that the default templates provided by MS always have a background color set.
I can't rationally explain why this matters, it's just one of those things to be written off as "magic".
Tuesday, April 7, 2009
Using Try-Catch in Transact-SQL
SQL 2005 implemented the TRY-CATCH form of trapping errors in SQL code. The old ON_Error statement no longer applies. This new construct is used in many languages today including C# and VB.NET to name a few. The basic concept is that you place your code within a Try and then use a Catch to find errors it may have encountered. Here is a very simple example you can run:
/* Simple Try Catch Example */
DECLARE @Denominator INT
SET @Denominator = 0
BEGIN TRY
SELECT 1/@Denominator AS [Output]
SELECT 'Computation did not fail' AS [message]
END TRY
BEGIN CATCH
SELECT ERROR_NUMBER() AS Error#, ERROR_MESSAGE() AS [MESSAGE];
GOTO EXITOR
END CATCH;
SELECT 'Catch Did Not Find Error'
EXITOR:
Now set the value of @Denominator to 1 or some other valid value. Notice how the flow of program execution changes.
/* Simple Try Catch Example */
DECLARE @Denominator INT
SET @Denominator = 0
BEGIN TRY
SELECT 1/@Denominator AS [Output]
SELECT 'Computation did not fail' AS [message]
END TRY
BEGIN CATCH
SELECT ERROR_NUMBER() AS Error#, ERROR_MESSAGE() AS [MESSAGE];
GOTO EXITOR
END CATCH;
SELECT 'Catch Did Not Find Error'
EXITOR:
Now set the value of @Denominator to 1 or some other valid value. Notice how the flow of program execution changes.
Monday, April 6, 2009
Enable Database Mail Alerts In SQL2008
While setting up our new SQL 2008 Boxes, I came across the interesting task of configuring SQL Mail. I mean, it would be nice to get an email when your job fails or logfiles grow too big, right? So I went to the web and started looking for articles describing the task.
The articles very nicely describe how to set up mail profiles and operators on your SQL Server. There is lots of material there, so I won't bother to add non-original content. But they do leave out a critical piece, which is to configure SQL Agent to use the profile you have defined. This is funny because my Systems Admin and I were trying to figure out how the two were tied together. The answer is on the Properties Tab of your SQL Agent. Just navigate to SQL Agent, Properties and you should see something like the below. Once you configure your profiles, set up your operators and fill in the below box, you should be good to go.
The articles very nicely describe how to set up mail profiles and operators on your SQL Server. There is lots of material there, so I won't bother to add non-original content. But they do leave out a critical piece, which is to configure SQL Agent to use the profile you have defined. This is funny because my Systems Admin and I were trying to figure out how the two were tied together. The answer is on the Properties Tab of your SQL Agent. Just navigate to SQL Agent, Properties and you should see something like the below. Once you configure your profiles, set up your operators and fill in the below box, you should be good to go.
Labels:
Database Mail,
sql 2008,
SQL Alerts,
SQLAgent,
SQLServer
Subscribe to:
Posts (Atom)


