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 |
|
dupati1
Posting Yak Master
123 Posts |
Posted - 2005-06-16 : 14:25:25
|
| Guys,I have this sql query requirement that looks daunting to me...Here is the situation...I have the following tableEquipNum EquipStatus_______________________2346732049 Y2346732050 Y2346732051 Y2346732052 N2346732053 Y2346732054 Y2346732055 Y2346732056 Y2346732057 Y---- and so onOk now i have a form with two fields (1)Enumber (2)ErangeThe user enters the first 6 numerals of the Equipnumber in the Enumber field and enter the number of comsecutive numbers he/she wants in the Erange field...For example...the user may enter 234673 and 3it means that he wants all the 3 or more blocks of the consecutive numbers with the equipment numbers starting with 234673 and with EquipStatus as Y...for the above data...the result should look likeEquipNum EquipStatus_______________________2346732049 Y2346732050 Y2346732051 Y2346732053 Y2346732054 Y2346732055 Y2346732056 Y2346732057 Yanother example may be 234673 and 5 then the results should be EquipNum EquipStatus_______________________2346732053 Y2346732054 Y2346732055 Y2346732056 Y2346732057 Ycan anyone help me writing this query...Thanks |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
|
|
dupati1
Posting Yak Master
123 Posts |
Posted - 2005-06-16 : 14:52:33
|
| Ok thanks...here is the DDL of my tableCREATE EquipTable( EquipNum float(8), EquipStatus Char(1) )Sample Data: INSERT INTO EquipTable(EquipNum,EquipStatus) VALUES(2346732057,'Y')I have tried something like this so far...SELECT Equipnum, EquipStatus FROM EquipTableWHERE Convert(varchar(10),Equipnum) LIKE '234673%' AND EquipStatus = YGROUP BY Equipnum, EquipStatusand got stuck..dint know how to get the range of values...Thanks |
 |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
|
|
dupati1
Posting Yak Master
123 Posts |
Posted - 2005-06-16 : 15:18:42
|
| I have tried something like this...DECLARE @EquipNum Float(8,0)DECLARE @Range IntSET @EquipNum = 2346732049SET @Range = 3SELECT Equipnum, EquipStatus FROM EquipTableWHERE Equipnum BETWEEN @EquipNum AND @EquipNum + @Range AND EquipStatus = 'Y'GROUP BY Equipnum, EquipStatusHAVING ( SELECT COUNT(Equipnum) FROM tblEquipment WHERE Equipnum BETWEEN @EquipNum AND @EquipNum + @Range AND EquipStatus = 'A' ) = @Rangebut it does not give me the results i want...i am trying to get blocks of data...Thanks |
 |
|
|
|
|
|
|
|