Click here to Skip to main content
15,900,392 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hello Friends,
I have suck at one place.
I have table named
RPT_MRFProgressDetails
which has column
MRFM_ReqdByDate, MPD_CurrReqdByDateRM

From front user can select from and to date using date control which is send in string format (dd/mm/yyyy) to SP.

Logic i want to use in SP is that.
1. Will check MPD_CurrReqdByDateRM is not null then it is between From and To Date.
2. If it is null, then will check MRFM_ReqdByDate is between
VB
From and To Date.


I have written logic in So as follows:
create procedure [dbo].[SP_RPTGetMRFsForResMgr]                         
(    
 @MRFM_FrDt varchar(10),                                    
 @MRFM_ToDt varchar(10)
)
as
begin
   select ..... from RPT_MRFProgressDetails
where convert(datetime,@MRFM_FrDt,103) <= isnull(MPD.MPD_CurrReqdByDateRM, MM.MRFM_ReqdByDate)
and convert(datetime,@MRFM_ToDt,103) >= isnull(MPD.MPD_CurrReqdByDateRM, MM.MRFM_ReqdByDate) 
end


Can we use parameter in left side and cloumns on right side of where clause?
Any other way to do this?

Thanks in advance :)
Posted
Comments
Richard C Bishop 9-May-13 9:57am    
Whats the problem?
dhage.prashant01 10-May-13 7:13am    
i jst wana know, using
where convert(datetime,@MRFM_FrDt,103) <= isnull(MPD.MPD_CurrReqdByDateRM, MM.MRFM_ReqdByDate)
in query wont affect the performance?
gvprabu 9-May-13 10:33am    
Check my solution... If any clarifications get back to me.

1 solution

Hi,
You can use COALSEC[^] and BETWEEN[^] logic for this. Try like this....
SQL
create procedure [dbo].[SP_RPTGetMRFsForResMgr]                         
(    
 @MRFM_FrDt varchar(10),                                    
 @MRFM_ToDt varchar(10)
)
as
begin
    select ..... from RPT_MRFProgressDetails
    where CONVERT(DATETIME,COALESCE(MPD_CurrReqdByDateRM,MRFM_ReqdByDate),103) BETWEEN @MRFM_FrDt AND @MRFM_ToDt 
end


Regards,
GVPrabu
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900