Re: creating data for a histogram.
Hi Erland,
Thanks Again for your time .
Explaination is good. So may I consider that the UDF will always be
little slower because the Query Optimizer can never arrange it for
optimization. but using function make query more manageable
Please correct me if my assumption is wrong.
I have yet another question (query ) .
I have two tables
One empmast which store emp current designation
Other promotion table which store the promotions of an employee during
his service.It stores the information of employee designation promotion
date.
Empmast(empid int primary key,desigid int references desigmast
,............)
PromotionDtls(e mpid int references Empmast,promota tedTo int references
desigmast, promotedFrom int references Desigmast,DateO fPromotion
smalldatetime)
EmpMast
empid desigid (current designation of employee)
1 3 ............... ............... .
2 1 ............... .........
PromotionDtls
empid promotedTo PromotedFrom effectiveDate
1 2 1 1-jan-2003
1 3 2 2-dec-2003
.............
Now I wish to use the designation Id in a query
such that if the employee data exists in Promotion Table the promotedTo
should be picked according to Effectivedate
otherwise the Empmast designation
e.g If I say desigId of employee having empid 1 on date 2-jun-2003 then
it should be desigId 2
I did this using isnull but I wish to find a better method.
select isnull( ( select top 1 promotedTo from promotionDtls where
empid=1 and effectivedate<' anygivendate' order by effectivedate desc )
, (select desigid from empmast where empid=1) )
It did give the result but looking for better method to solve this.
With regards
Jatinder Singh
Hi Erland,
Thanks Again for your time .
Explaination is good. So may I consider that the UDF will always be
little slower because the Query Optimizer can never arrange it for
optimization. but using function make query more manageable
Please correct me if my assumption is wrong.
I have yet another question (query ) .
I have two tables
One empmast which store emp current designation
Other promotion table which store the promotions of an employee during
his service.It stores the information of employee designation promotion
date.
Empmast(empid int primary key,desigid int references desigmast
,............)
PromotionDtls(e mpid int references Empmast,promota tedTo int references
desigmast, promotedFrom int references Desigmast,DateO fPromotion
smalldatetime)
EmpMast
empid desigid (current designation of employee)
1 3 ............... ............... .
2 1 ............... .........
PromotionDtls
empid promotedTo PromotedFrom effectiveDate
1 2 1 1-jan-2003
1 3 2 2-dec-2003
.............
Now I wish to use the designation Id in a query
such that if the employee data exists in Promotion Table the promotedTo
should be picked according to Effectivedate
otherwise the Empmast designation
e.g If I say desigId of employee having empid 1 on date 2-jun-2003 then
it should be desigId 2
I did this using isnull but I wish to find a better method.
select isnull( ( select top 1 promotedTo from promotionDtls where
empid=1 and effectivedate<' anygivendate' order by effectivedate desc )
, (select desigid from empmast where empid=1) )
It did give the result but looking for better method to solve this.
With regards
Jatinder Singh
Comment