Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Shaun E on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

stored procedure

Status
Not open for further replies.

angela4eva

Programmer
Apr 29, 2005
46
US
I have a stored procedure and there have been some isuues recarginf the dates and i have to hordcode some dates ..can any one please let me know how i can accomplish times
here is my stored proc.can i write a conditional if..

@startdate datetime
@enddate datetime
select number1,name from log where transdate>=@startdate and transdate<@enddate

---here what i need to accomplish

@startdate datetime
@enddate datetime
---if @startdate='11/19/2006' and @enddate='11/20/2006' then
select number1,name from log where transdate>='11/20/2006 1:00pm' and transdate< '11/20/2006'
-------if @startdate='11/20/2006' and @enddate='11/21/2006' then
select number1,name from log where transdate>='11/20/2006 1:00pm' and transdate< '11/20/2006'
default
select number1,name from log where transdate>=@startdate and transdate<@enddate
 
Ok....first things first here.........

Any date without a time defaults as 00:00:00.000. So,
Code:
select number1,name 
from log 
where transdate>='11/20/2006 1:00pm' 
  and transdate< '11/20/2006'

is really:
Code:
select number1,name 
from log 
where transdate>='11/20/2006 1:00pm' 
  and transdate< '11/20/2006 00:00:00.000'

Which I'm sure ISN'T what you want as no data will match that. So, what endtime do you really want?

-SQLBill



Posting advice: FAQ481-4875
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top