The Wiert Corner – irregular stream of stuff

Jeroen W. Pluimers on .NET, C#, Delphi, databases, and personal interests

  • My badges

  • Twitter Updates

  • My Flickr Stream

  • Pages

  • All categories

  • Enter your email address to subscribe to this blog and receive notifications of new posts by email.

    Join 1,862 other subscribers

Archive for the ‘SQL Server 2000’ Category

SQL Server inverse of (equals) is ((not equals) or (is NULL)

Posted by jpluimers on 2011/12/07

Usually getting queries right with SQL Server comes down to handling NULL correctly.

For instance, on this table:

MYTABLE
ID LAST_NAME
6 COUNT(*)
1 FOO
2 BAR
3 FOO
4 **NULL**
5 BAR
6 FOO

What are the results of these SELECT statements

SELECT COUNT (*)
FROM MYTABLE

SELECT COUNT (*)
FROM MYTABLE
WHERE     (LAST_NAME = 'FOO')

SELECT COUNT (*)
FROM MYTABLE
WHERE     (LAST_NAME <> 'FOO')

SELECT COUNT (*)
FROM MYTABLE
WHERE     NOT (LAST_NAME = 'FOO')

You might think they are like these, as LASTNAME <> ‘FOO’ looks like the inverse of LASTNAME = ‘FOO’:

  • 6
  • 3
  • 3
  • 3

But in fact the results are these:

  • 6
  • 3
  • 2
  • 2

When you look closely to the SQL statements below, you will see that the inverse of EQUALS contains an IS NULL, the same for the inverse of NOT EQUALS:

SELECT COUNT (*)
FROM MYTABLE

-- inverse of NOT EQUALS
SELECT COUNT (*)
FROM MYTABLE
WHERE     (LAST_NAME = 'FOO') OR (LAST_NAME IS NULL)

SELECT COUNT (*)
FROM MYTABLE
WHERE     (LAST_NAME <> 'FOO')

SELECT COUNT (*)
FROM MYTABLE
WHERE     (LAST_NAME = 'FOO')

-- inverse of EQUALS
SELECT COUNT (*)
FROM MYTABLE
WHERE     (LAST_NAME <> 'FOO') OR (LAST_NAME IS NULL)

-- inverse of EQUALS
SELECT COUNT (*)
FROM MYTABLE
WHERE     (NOT (LAST_NAME = 'FOO')) OR (LAST_NAME IS NULL)
  • 6
  • 4
  • 2
  • 3
  • 3
  • 3

Lesson learned: always take into account NULL when trying to formulate your SQL comparisons well.

–jeroen

Posted in Database Development, Development, SQL Server, SQL Server 2000, SQL Server 2008 | Leave a Comment »

SQL Server 2000: export SQL Query Analyzer result data to Excel/CSV and more

Posted by jpluimers on 2011/11/16

I just visited a client which is still using SQL Server 2000, and not upgraded their tool set, nor allows different tools to be installed.

Which means back to basics, re-adjusting the project planning and frantically trying to remember things from the past.

Boy am I spoiled with a current toolset :)

This goes from simple things like saving a result set from the SQL Query Analyzer:

  1. Select a cell
  2. Press Ctrl-A to select all rows
  3. Right click in the grid and select “Copy” (to copy the cells as CSV) or “Save As” (to export the cells as CSV)

along the absence of support for XML, MARS, error handling (not even talking about spatial data!) to the way that in SQL Server 2000 DTS (Data Transformation Services) has its own mind of date/time format handing while importing stuff.

But it sure helps setting aims for the scheduled migration process to the far more current SQL Server 2008 R2 :)
(Mental note: migrating the SQL Server 2000 DTS packages to SQL Server 2008 R2 will be a challange).

Oh, some of the SQL Queries that come in handy when moving stuff around in an OTAP/DTAP environment:

1. Selecting relevant DTS packages (that are always in the MSDB database)

select
name
from msdb..sysdtspackages -- 2005: sysdtspackages90; 2008: sysssispackages
where
name like '%my-app-ID%'

2. Selecting relevant objects from a database (watch the xtype values that can exist in SQL Server 2000)

using my-database
select 
name, xtype
from 
sysobjects
where 
name like '%my-app-id%'
and xtype in ('U', 'V', 'TR', 'P', 'X') -- tables/views/triggers/procedures/xprocedures only
order by xtype, name

Blast from the past :)

–jeroen

via: export sql query analyzer data to excel SQL Server.

PS: For the statistics, SQL Server 2000 has been EOL for a while; mainstream support ended in 2008, extended support ends in 2013.

Posted in CSV, Database Development, Development, Software Development, SQL, SQL Server, SQL Server 2000 | Leave a Comment »

StarTeam 2005 on Windows 2003 Server using MSDE: service dependencies

Posted by jpluimers on 2010/08/24

Recently, I had to restore StarTeam 2005 on a Windows 2003 Server.

An out-of-the-box install using MSDE 2000 does not want to run as a service.

This post shows you how I solved that problem. Read the rest of this entry »

Posted in Database Development, Development, MSDE 2000, Power User, Software Development, Source Code Management, SQL Server, SQL Server 2000, StarTeam, Windows, Windows Server 2003 | Leave a Comment »