473,401 Members | 2,139 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,401 software developers and data experts.

Dates stored procedure

I am using SQL Server 2000, and I want to write a stored procedure that returns certain values either between 2 dates (start and end) or the user enters a particular string. Its grafts a bit , but the dates are not returning true data

ALTER PROCEDURE proc_CBLSearch
@OrderNo VARCHAR(50) = '',
@BizReqID VARCHAR(50) = '',
@NameOnCard VARCHAR(50) = '',
@DocHolder VARCHAR(50) = '',
@SystemRef VARCHAR(50) = '',
@StartDate DATETIME = 0,
@EndDate DATETIME = 0

AS



IF @StartDate = 0 or @StartDate is null
BEGIN
SELECT @StartDate = 0
END

IF @EndDate = 0 or @EndDate is null
BEGIN
SELECT @EndDate = GETDATE()
END

-- You need to enter the @strSearch
-- This can be BizReqID,DocID, Doc Holder Name, MyMarket Order


SELECT DISTINCT
--CBL.DocumentHeight,
--CBL.DocumentWidth,
--CBL.DocumentUnit,
CBL.SentDate,
CBL.SystemRef,
DocumentDefinition.ItemName,
XMLExtract.DocHolder,
XMLExtract.NameOnCard,
XMLExtract.Company,
XMLExtract.BizcardOrderID,
XMLExtract.BizReqID,
MyMarket.OrderNo

FROM CBL
INNER JOIN Offerings
ON CBL.OfferingID = Offerings.OfferingID
INNER JOIN DocumentDefinition
ON CBL.DocumentDefinitionID = DocumentDefinition.DocumentDefinitionID
INNER JOIN Users
ON CBL.UserID = Users.UserID
LEFT OUTER JOIN XMLExtract
ON CBL.SystemRef = XMLExtract.BizcardOrderID
LEFT OUTER JOIN MyMarket
ON XMLExtract.BizReqID = MyMarket.BizReqID
WHERE (
CBL.PrinterID = 43
OR
CBL.PrinterID = 45
)
AND CBL.BatchStatus = 1
AND

(

(CBL.SentDate BETWEEN @StartDate AND @EndDate)

OR ((
@OrderNo = ''
OR
MyMarket.OrderNo LIKE '%' + @OrderNo + '%'
)
AND (
@BizReqID = ''
OR
XMLExtract.BizReqID LIKE '%' + @BizReqID + '%'
)
AND (
@NameOnCard = ''
OR
XMLExtract.NameOnCard LIKE '%' + @NameOnCard + '%'
)
AND (
@SystemRef = ''
OR
CBL.SystemRef LIKE '%' + @SystemRef + '%'
)
AND (
@DocHolder = ''
OR
XMLExtract.DocHolder LIKE '%' + @DocHolder + '%'
)))
ORDER BY CBL.SentDate
Sep 28 '07 #1
0 963

Sign in to post your reply or Sign up for a free account.

Similar topics

19
by: Lauren Quantrell | last post by:
I have a stored procedure using Convert where the exact same Convert string works in the SELECT portion of the procedure but fails in the WHERE portion. The entire SP is listed below....
10
by: Robert Zirpolo | last post by:
For some reason a stored procedure which I have created is incorrectly saving the date to the table. It seems the day and month are being swapped around e.g. a date which should be the 12th April...
6
by: Sam | last post by:
Hi, In SQL Server when I create a stored procedure, in the list of stored procedures the Create Date column used to be formatted as: 28/09/2004 14:35:24 But since yesterday, for some reason, when...
2
by: Dino L. | last post by:
How can I run stored procedure (MSSQL) ?
5
by: AAJ | last post by:
Hi Does anyone know of any good publically available set of standards for managing dates when dealing with a database server (in my case SQL Server 2000 and c# VS2005). At the moment, if I...
2
by: Eamon | last post by:
Hi all, I'm trying to find a way to list all the jobs/schedules due to run between two dates but all I seem to be able to get is a list of jobs with their NextRunTime. Example: Say I had two...
4
by: Jeff Goodman | last post by:
If there is a better newsgroup to post this in, please let me know. I am a relatively new VB.NET/SQL 2000 programmer. I am working with data imported into SQL2K from Access. Many of the dates...
4
by: Richd | last post by:
HI, Any help would be appreciated, I am trying to use dates to show things as past due (yesterday and earlier are past due). Problem:Because of space constraints on the form the stored procedure...
2
by: daffy2 | last post by:
Simple as it might seem this has defeated me so far. I want to enter sequential dates for say 1 year in a table by means of a stored program. I can attach one of my many effoorts if it helps. ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.