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.
| Author |
Topic |
|
Mng
Yak Posting Veteran
59 Posts |
Posted - 2009-08-27 : 03:20:12
|
| Hi, i have a student table with 100 records. The table contains column "SNO" which is an int field starts with 101 and ends with 200. i have deleted randomly some of the student records.Now i want to know what are the Students i had deleted( I mean i wnat SNO)SNO SNAME101 abc102 deef105 ght115 456------so on200 xyzNow i want the missing SNO from the table. how to query for this. |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2009-08-27 : 03:45:43
|
| Search for Find gaps+SQL Server in googleMadhivananFailing to plan is Planning to fail |
 |
|
|
waterduck
Aged Yak Warrior
982 Posts |
Posted - 2009-08-27 : 04:35:55
|
[code]SELECT n.number, s.SNOFROM master..spt_values n LEFT JOIN Students s ON n.number = s.SNOWHERE n.type = 'P' AND n.number >= 101 AND n.number <= 200 AND s.SNO IS NULL [/code]quick but not lasting solution Hope can help...but advise to wait pros with confirmation... |
 |
|
|
Mng
Yak Posting Veteran
59 Posts |
Posted - 2009-08-27 : 06:02:13
|
Thank youquote: Originally posted by waterduck
SELECT n.number, s.SNOFROM master..spt_values n LEFT JOIN Students s ON n.number = s.SNOWHERE n.type = 'P' AND n.number >= 101 AND n.number <= 200 AND s.SNO IS NULL quick but not lasting solution Hope can help...but advise to wait pros with confirmation...
|
 |
|
|
ashishashish
Constraint Violating Yak Guru
408 Posts |
Posted - 2009-08-27 : 06:27:08
|
| create table serialno(sno int)declare @i intset @i=101while @i<=200begininsert into serialno values(@i)set @i=@i+1endselect * from serialnodelete from serialno where sno in(101,105,145,123,178,136,111,198,123,145)select number as Sno from master..spt_values where number not in(select sno from serialno) and type='P' and number between 101 and 200iF theRe iS a wAy iN tHen theRe iS a wAy oUt.. |
 |
|
|
|
|
|
|
|