Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Datetime error running SQL SP for Crystal Report

Author  Topic 

Jonu2
Starting Member

2 Posts

Posted - 2009-11-23 : 23:16:54
Hi, I'm very new to SQL and Crystal Reporting but am trying to enhance an old report so that if no date range is input via the HTML criteria selection then it will default to a fromdate of six months previous and a todate of six months in the future.

(Currently this report will produce no data if neither date is specified as they both default to 01-01-1900)

The sp used starts with the below code and I only changed the last bit that is highlighted in red. When I run it, it gives me an error indicating that it doesn't know what DATETIME is - it doesn't seem to recognise DATETIME. I know I'm probably doing something very basic wrong but I'd really appreciate being pointed in the right direction please, many thanks:

ALTER procedure [dbo].[NCS_AuditReport_Sp]
@ServiceCustomerID nvarchar(30),
@ResourceID nvarchar(30),-- Auditor
@Sector varchar(40), -- Customer Group
@State nvarchar(16), -- ServiceStateCode
@TaskName varchar(100),
@WorkTypeCode varchar(1000),
@FromDate datetime,
@ToDate datetime,
@Standard nvarchar(20) --MOD005

as

/*
** Confidential Information
** Limited Distribution of Authorized Persons Only
** Created 2005 and Protected as Unpublished Work
** Under the U.S. Copyright Act of 1976
** Copyright (c) 2001-2005 Epicor Software Corporation
** All Rights Reserved
**
** Rev. Name Date Reference Description
** ****** ********** ********** ************** ********************
** MOD001 TJK 2007-08-28 N/A Re-write the whole thing
** MOD002 TJK 2007-11-30 N/A Correct the join to the Client Infopath tables
** MOD003 Marketta R 2009-01-19 Change Division codes to names
**
** EXAMPLE Procedure Call

EXEC "NCS_AuditReport_Sp"
NULL,
'DPOWER',
NULL,
NULL,
NULL,
NULL,
'2007-07-01 00:00:000',
'2007-08-31 00:00:000',
NULL

EXEC "NCS_AuditReport_Sp"
'12023000',
'DPOWER',
'522',
'SA',
'EMS',
'40QAS',
'2007-07-01 00:00:000',
'2007-08-31 00:00:000',
'EMS'

*/


-- Creating a temp table to hold records for the audit report
create table #AuditReport (
ProjectCode varchar(40),
ServiceCustomerID nvarchar(30),
ServiceCustomerName nvarchar(240),
BillToID nvarchar(30),
BillToName nvarchar(240),
Status char,
ServiceStandard nvarchar(40),
ServiceStateCode nvarchar(16),
SectorCode nvarchar(12),
SectorName nvarchar(60),
ClientManagerID nvarchar(30),
ClientManagerFirstName varchar(120),
ClientManagerLastName varchar(120),
TaskUID int,
TaskName nvarchar(120),
PlannedHours decimal(8,2),
BookedHours decimal(8,2),
WorkTypeCode varchar(24),
WorkTypeDesc varchar(60),
StartDate datetime,
EndDate datetime,
CompleteFlag int,
City nvarchar(50),
ProjectPrimaryResource varchar(120), --MOD001
)

-- MOD001 Update client manager name
select distinct client_code, client_manager
into #ClientManager
FROM ncs_client_certification (NOLOCK)
WHERE client_manager IS NOT NULL
--MOD007 WHERE Client_code like @ServiceCustomer

-- Get WHERE clause parameter
declare @ServiceCustomer nvarchar(100),
@Auditor nvarchar(100),
@CustomerGroup varchar(100),
@ServiceState nvarchar(100),
@TaskDesc varchar(2000),
@WorkType nvarchar(200),
@Stand nvarchar(100)

-- If dates are blank then set dates as 6 months ago to 6 months forward

if (@FromDate = 0 or @FromDate ='' or @FromDate is null or @FromDate = '1900-01-01 00:00:00.000')
and (@ToDate = 0 or @ToDate ='' or @ToDate is null or @ToDate = '1900-01-01 00:00:00.000')
begin
select dateadd(month,-6,datetime) as StartDate
select dateadd(month,6,datetime) as EndDate
end

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2009-11-23 : 23:47:56
Moved this topic from the Article Discussion forum since this isn't an article.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog

"Let's begin with the premise that everything you've done up until this point is wrong."
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2009-11-25 : 01:28:26
You should use getdate() in place of datetime

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -