You are here: Locate rows in table where column value missing (I think!) « MsSQL Server « IT news, forums, messages
Locate rows in table where column value missing (I think!)

Posted by teddysnips on 02/08/07 13:06

SQL 2k, DDL below.

I have a simple table with the following data:

fldYear fldCode1 fldCode2
2000 ABC1 ABC12
2000 ABC1 ABC13
2001 ABC1 ABC12
2002 ABC1 ABC12
2002 ABC1 ABC13

I need to know, for every distinct combination of fldCode1 and
fldCode2, if there are any years missing.

For example,

SELECT DISTINCT fldCode1, fldCode2 FROM MyTable

returns
ABC1 ABC12
ABC1 ABC13

I need to know that in 2001 there was no entry for ABC1/ABC13

Thanks!

Edward

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].
[MyTable]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[MyTable]
GO

CREATE TABLE [dbo].[MyTable] (
[fldYear] [char] (10) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[fldCode1] [char] (10) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[fldCode2] [char] (10) COLLATE SQL_Latin1_General_CP1_CI_AS NULL
) ON [PRIMARY]
GO

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация