| Author |
Topic |
|
baburk
Posting Yak Master
108 Posts |
Posted - 2008-12-20 : 02:00:11
|
| Hi,DECLARE @Sample TABLE ( StationID INT, Value INT )INSERT @SampleSELECT 1, 3 UNION ALLSELECT 1, 2 UNION ALLSELECT 1, 4 UNION ALLSELECT 1, 5 UNION ALLSELECT 1, 1 UNION ALLSELECT 1, 8 UNION ALLSELECT 1, 6 UNION ALLSELECT 1, 7 UNION ALLSELECT 2, 8 UNION ALLSELECT 2, 6 UNION ALLSELECT 2, 7 UNION ALLSELECT 2, 5 UNION ALLSELECT 2, 1 UNION ALLSELECT 2, 3 UNION ALLSELECT 2, 2 UNION ALLSELECT 2, 4SELECT StationID, Value FROM @Sample WHERE StationID = 2 AND Value BETWEEN 5 AND 7I wants to get Valueas in these ways.How can I?StationID Value1 51 61 71 51 41 31 21 11 81 7Thanks in advance. |
|
|
bklr
Master Smack Fu Yak Hacker
1693 Posts |
Posted - 2008-12-22 : 01:28:35
|
| select identity(int,1,1)AS id ,stationid,value into #temp from @sample where stationid = 1 and value between 5 and 7 insert into #temp select '',''insert into #tempselect * from @sample where stationid = 1 select stationid , value from #temp order by id |
 |
|
|
baburk
Posting Yak Master
108 Posts |
Posted - 2008-12-22 : 02:54:48
|
quote: Originally posted by bklr select identity(int,1,1)AS id ,stationid,value into #temp from @sample where stationid = 1 and value between 5 and 7 insert into #temp select '',''insert into #tempselect * from @sample where stationid = 1 select stationid , value from #temp order by id
Thanks for your reply.stationid value1 51 61 70 01 31 21 41 51 11 81 61 7Here 6 should not come.Since we give only 5 and 7 |
 |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2008-12-22 : 03:02:22
|
[code]DECLARE @Sample TABLE ( StationID INT, Value INT )INSERT @SampleSELECT 1, 3 UNION ALLSELECT 1, 2 UNION ALLSELECT 1, 4 UNION ALLSELECT 1, 5 UNION ALLSELECT 1, 1 UNION ALLSELECT 1, 8 UNION ALLSELECT 1, 6 UNION ALLSELECT 1, 7 UNION ALLSELECT 2, 8 UNION ALLSELECT 2, 6 UNION ALLSELECT 2, 7 UNION ALLSELECT 2, 5 UNION ALLSELECT 2, 1 UNION ALLSELECT 2, 3 UNION ALLSELECT 2, 2 UNION ALLSELECT 2, 4DECLARE @StationID INT, @LowLevel INT, @HighLevel INTSELECT @StationID = 2, @LowLevel = 5, @HighLevel = 7-- Peso 1SELECT StationID, ValueFROM ( SELECT StationID, Value, 0 AS grp, Value AS ordnung FROM @Sample WHERE StationID = @StationID AND Value >= @LowLevel AND Value <= @HighLevel UNION ALL SELECT StationID, Value, 1, @LowLevel - Value FROM @Sample WHERE StationID = @StationID AND Value <= @LowLevel UNION ALL SELECT StationID, Value, 2, @HighLevel - Value FROM @Sample WHERE StationID = @StationID AND Value >= @HighLevel ) AS dORDER BY grp, ordnung[/code] E 12°55'05.63"N 56°04'39.26" |
 |
|
|
bklr
Master Smack Fu Yak Hacker
1693 Posts |
Posted - 2008-12-22 : 03:08:11
|
quote: Originally posted by baburk
quote: Originally posted by bklr select identity(int,1,1)AS id ,stationid,value into #temp from @sample where stationid = 1 and value between 5 and 7 insert into #temp select '',''insert into #tempselect * from @sample where stationid = 1 select stationid , value from #temp order by id
Thanks for your reply.stationid value1 51 61 70 01 31 21 41 51 11 81 61 7Here 6 should not come.Since we give only 5 and 7
Welcome select identity(int,1,1)AS id ,stationid,value into #temp from @sample where stationid = 1 and value between 5 and 7 insert into #temp select '',''insert into #tempselect * from @sample where stationid = 1 and value <> 6select stationid , value from #temp order by id o/p as1 51 61 70 01 31 21 41 51 11 81 7 |
 |
|
|
|
|
|