Log errors with SQL

by Marre 10. May 2010 10:25
How do I get the error information if f ex an insert fails? Well, I did it this way:
 
Declare @error_number int;
Declare @error_desc nvarchar(max);
 
set @error_number = @@error;
if @error_number <> 0
begin
set @error_desc = (select substring(description,1,60) from master.dbo.sysmessages where error = @error_number);
insert into my_log values ('This is where I log errors with error number, error description, a date, procedure name and where in the procedure');
end
 
 
Not that hard :) 

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags:

SQL

SQL - data not in both tables

by Marre 24. February 2010 15:34

I have two tables with a lot of data. I have to compare them and find out if there are data in table 1 that does not exist in table 2.

Well. I could use this script:

SELECT
name
FROM
table1
WHERE
name NOT IN (SELECT name FROM table2) 

 But since it´s a lot of data in those tables, it will take a while. This script will do it faster: 

SELECT
tbl2.name
FROM
table1 tbl1
RIGTH OUTER JOIN table2 tbl2 ON tbl1.name = tbl2.name
WHERE
tbl1.name IS NULL

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags:

SQL

MS SQL Server slow at authenication

by Marre 22. June 2009 13:04

Have you ever had problems when logging on to an database with SQL Server Manager. The manager is slow. Almost frozen. There is a little bit strange solution to this problem. 

Open Internet Explorer. Go to Internet Options -> Security and uncheck 'Check for publishers certificate revocation'. Viola...That´s it :) 

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags:

Other | SQL

Find duplicates with SQL

by Marre 7. October 2008 11:53
Recently I needed to find out if one of my tables contained
duplicates. It resulted in this script:
SELECT Name, COUNT(Name) AS NoOfDuplicates
FROM tblCustomers
GROUP BY Name
HAVING (COUNT(Name) > 1)
I select the name and no of occurrences in my table.
I only select those who have more than one occurrence

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags:

SQL

Powered by BlogEngine.NET 1.4.5.0
Theme by Supremelink Development

Martin Andersson

I´m currently working as senior consultant for Capgemini Norway AS.

Curriculum vitae

I use this blog when I find something useful that I want to be able to get hold of wherever I need. But who knows...Maybe someone else will find it useful as well.


About

Supremelink is the name of where I collect my spare time projects. The idea is to learn more about new techniques and areas that I´m not usually is working with or that can be nice to know before future projects at work.

To see the benefits with new technologies and to achieve as much knowledge about those areas, I usually have a goal/project to work with.

This site run´s on BlogEngine.NET. It´s a full featured blog that is using XML as data source. No database is required.

Supreme Software

When I find software that I like and of whitch I can see the benefits to use, I write about it under the category "Supreme Software".

Beware of the soon coming updates in this category!

Tag cloud