| Author |
Topic |
|
jocast
Starting Member
8 Posts |
Posted - 2010-06-15 : 15:21:20
|
| Hello group i am trying to get the "missing boxes" from a query. Here i post an example.Table1BoxID, noxnumber, boxqty, boxgroup12345, 1 , 3 , abcd12345, 3 , 3 , abcd23456, 1 , 2 , abcd23456, 2 , 2 , abcd34567, 4 , 4 , abcdMy goal is to let the user know the missing boxesBoxID, noxnumber, boxqty, boxgroup12345, 2 , 3 , abcd34567, 1 , 4 , abcd34567, 2 , 4 , abcd34567, 2 , 4 , abcdis this possible? |
|
|
vijayisonly
Master Smack Fu Yak Hacker
1836 Posts |
Posted - 2010-06-15 : 16:01:29
|
I'm sure there must be a better way...but try this.Sample Datadeclare @t table (BoxID int, noxnumber int, boxqty int, boxgroup varchar(10))insert @tselect 12345, 1 , 3 , 'abcd'union all select 12345, 3 , 3 , 'abcd'union all select 23456, 1 , 2 , 'abcd'union all select 23456, 2 , 2 , 'abcd'union all select 34567, 4 , 4 , 'abcd' Queryselect t1.*from(select distinct a.BoxID,b.number,a.boxqty,a.boxgroupfrom(select BoxID,boxqty,max(noxnumber) as noxnumber ,boxgroup from @tgroup by BoxID,boxqty,boxgroup) across apply(select number from master..spt_values where number between 1 and a.noxnumber ) b) t1left join @t t2on t1.BoxID = t2.BoxID and t1.number = t2.noxnumberwhere t2.noxnumber is null ResultBoxID number boxqty boxgroup----------- ----------- ----------- ----------12345 2 3 abcd34567 1 4 abcd34567 2 4 abcd34567 3 4 abcd |
 |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2010-06-15 : 18:27:39
|
select number from master..spt_values where number between 1 and a.noxnumber select number from master..spt_values where number between 1 and a.noxnumber and type = 'p' N 56°04'39.26"E 12°55'05.63" |
 |
|
|
|
|
|