|
erwine
Yak Posting Veteran
69 Posts |
Posted - 2006-06-01 : 23:34:12
|
| declare @startdate datetime, @enddate datetimeset @startdate = '20060101'set @postdate = '20060131'create table Employee(empNo varchar(3))insert into Employeeselect '100' unionselect '101' unionselect '102' create table Scheme(empNo varchar(3),empSch varchar(2),wefDate datetime )insert into Schemeselect '100','1', '20060101' unionselect '100','2', '20060110' unionselect '100','3', '20060125' unionselect '101','4', '20051215' unionselect '101','3', '20051230' unionselect '101','6', '20060125' unionselect '102','7', '20060110' my program is currently using 2 while loops to :1st loop : for each employee In table Employee select top 1 * from Scheme where wefDate <= @startdate order by wefDate desc union select * from Scheme where wefDate between @startdate and @enddatenext this should give me access to:'100','1', '20060101''100','2', '20060110''100','3', '20060125''101','3', '20051230' '101','6', '20060125' '102','7', '20060110'My qst is how am i going to have these 6records shown if i wanna use SQL query instead of using program. From those 2tables, i wanna have :'100','1', '20060101''100','2', '20060110''100','3', '20060125''101','3', '20051230' '101','6', '20060125' '102','7', '20060110'anyone? Thx... sql is fun... |
|