Wrox Home  
Search P2P Archive for: Go

  Return to Index  

sql_language thread: Please Help - Another stored procedure question


Message #1 by savoym@h... on Mon, 30 Dec 2002 14:21:24
Brian,

Your time and help are appreciated, thank you!  That got it!!



> Datetime fields include time so you need to change the where clause to 
be
select from 12:00 current date to 11:59PM current date.  There are lots 
of
ways to do it. one is:

CREATE PROCEDURE Get_Error_Messages

AS

DECLARE @date datetime
DECLARE @date2 datetime
set @date=convert(datetime,convert(varchar(10),getdate(),101)) --current
date with no time so get's 12:00AM
set @date2=dateadd(day,1,@date)
SELECT	Error_ID, HCIN_User_ID, Session_ID, Request_Method, 
Server_Port,  HTTPS, Local_Address, Remote_Address, 
HTTP_User_Agent, URL, Form_Data,
All_HTTP, IIS_Error_code, COM_Error_code, Error_source_code, 
Error_category,
Error_file, Error_line, Error_abbrev_description, 
Error_detail_description, DB_Error_number, DB_Error_description, 
DB_Error_source, DB_Error_sqlstate,
DB_Error_nativeerror, Created_date

FROM error_log

WHERE created_date between @date and @date2


Good luck.

This uses the convert function from date to varchar to date to remove the
time from the getDate() function.  Then uses dateAdd to get the next day 
so
if current time is 12/30/02 9:30AM we get @date='12/30/02' and
@date2='12/31/02'

Brian Freeman
(770) 916-0595 ext. 415
Carnegie Technologies/Bluewave Computing 
www.carnegie.com and www.bluewave-computing.com

-----Original Message-----
From: savoym@h... [mailto:savoym@h...]
Sent: Monday, December 30, 2002 9:21 AM
To: sql language
Subject: [sql_language] Please Help - Another stored procedure question


I am trying to find all error messages in my error_log table that have 
been created for today's date.  The created_date field has a data type 
of "datetime".  Any direction or help would be appreciated.  

Thanks!!  

Here is my SP code:

CREATE PROCEDURE Get_Error_Messages

AS

DECLARE @date datetime
SET @date = getdate()

SELECT	Error_ID, HCIN_User_ID, Session_ID, Request_Method, 
Server_Port,  HTTPS, Local_Address, Remote_Address, 
HTTP_User_Agent, URL, Form_Data,
All_HTTP, IIS_Error_code, COM_Error_code, Error_source_code, 
Error_category,
Error_file, Error_line, Error_abbrev_description, 
Error_detail_description, DB_Error_number, DB_Error_description, 
DB_Error_source, DB_Error_sqlstate,
DB_Error_nativeerror, Created_date

FROM error_log

WHERE created_date = @date
GO


---
Change your mail options at http://p2p.wrox.com/manager.asp or 
to unsubscribe send a blank email to



  Return to Index