Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Numbers in sequence?

Author  Topic 

RickD
Slow But Sure Yak Herding Master

3608 Posts

Posted - 2007-11-19 : 11:46:49
Hi,

I have a bit of an issue. I have 3 columns in 3 different tables and I need to find out if the values are in the correct sequence.

declare @Table1 table (number int, number1 int)
declare @Table2 table (number int, Outputfile varchar(100))
declare @Table3 table (number int, SequenceNo int)

insert into @Table1
select 1,4500
union select 2,4501
union select 3,4503
union select 4,4504
union select 5,5501
union select 6,5502
union select 7,5504

insert into @Table2
select 1, 'First Output'
union select 2, 'First Output'
union select 3, 'First Output'
union select 4, 'First Output'
union select 5, 'Second Output'
union select 6, 'Second Output'
union select 7, 'Second Output'

insert into @Table3
select 1, 1
union select 2,2
union select 3,5
union select 4,4
union select 5,3
union select 6,2
union select 7,1

select t1.number, t2.Outputfile, t3.SequenceNo
from @Table2 t2
inner join @Table3 t3
on t3.number = t2.number
inner join @Table1 t1
on t1.number = t3.number
order by t2.Outputfile, t1.number1

What I have so far is the above, but in reality I have over a million rows to check and am racking my brains to find a way to check this automatically. Can anyone help?

dinakar
Master Smack Fu Yak Hacker

2507 Posts

Posted - 2007-11-19 : 12:17:36
quote:
Originally posted by RickD

.....I need to find out if the values are in the correct sequence.


which "ValueS" are you taling about? Number/outputfile/sequenceNo?

Dinakar Nethi
************************
Life is short. Enjoy it.
************************
http://weblogs.sqlteam.com/dinakar/
Go to Top of Page

RickD
Slow But Sure Yak Herding Master

3608 Posts

Posted - 2007-11-20 : 03:35:49
Sequence number, so I want to know that the sequenceno for the 3rd record in the first output is greater than the 4th record and that the whole of the Second Output figures are wrong.


3 First Output 5
4 First Output 4
5 Second Output 3
6 Second Output 2
7 Second Output 1


Thanks
Go to Top of Page

RickD
Slow But Sure Yak Herding Master

3608 Posts

Posted - 2007-11-20 : 06:41:12
Well, I got my result, but had to resort to a cursor to do it, now I feel dirty.. ;)
Go to Top of Page
   

- Advertisement -