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
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Parameter problem

Author  Topic 

muzzettemm
Posting Yak Master

212 Posts

Posted - 2008-11-03 : 18:19:16
Hi all I have a stored procedure that gives users the option to either enter in a end Date and Start date or the Name. I get the correct results when i enter in a name but I get no results when I enter in the Start Date adn End date. Can someone help me please, I'll bet its something silly that I overlooked.

SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER PROCEDURE [dbo].[SearchVendor_Fees]
@Start_Date DATETIME = NULL,
@End_Date DATETIME = NULL,
@Enter_VendorName NVARCHAR(255)
AS
SELECT VendorLicense.VendorName, VendorLicense.VendorLicNumber, VendorFees.DebitAmount,
VendorFees.CreditAmount, VendorFees.Date, VendorFees.CheckNumber, VendorFees.Subtotal
FROM VendorFees INNER JOIN
VendorLicense ON VendorFees.VendorLicNumber = VendorLicense.VendorLicNumber
WHERE (@Start_Date is null or VendorFees.[Date] <= @Start_Date)
AND(@End_Date is null or VendorFees.[Date] >= @End_Date)
AND (VendorLicense.VendorName LIKE @Enter_VendorName + '%')

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2008-11-03 : 18:23:16
You probably want: Column1 >= @sd AND Column1 <= @ed.

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

Subscribe to my blog
Go to Top of Page

muzzettemm
Posting Yak Master

212 Posts

Posted - 2008-11-03 : 19:08:57
I tried that and for some reason it didnt work
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2008-11-03 : 19:22:20
Could you show us exactly what you tried and also what parameters you passed to the stored procedure?

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

Subscribe to my blog
Go to Top of Page

muzzettemm
Posting Yak Master

212 Posts

Posted - 2008-11-03 : 19:27:26
the parameters I entered was 10/01/2008 to 10/31/2008 and I tried to changing from

SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER PROCEDURE [dbo].[VendorFee_Totals]
@Start_Date DATETIME = NULL,
@End_Date DATETIME = NULL
AS

SELECT VendorLicense.VendorName, VendorLicense.LicenseIssueDate, VendorLicense.VendorLicNumber, VendorFees.DebitAmount,
VendorFees.CreditAmount, VendorFees.Date, VendorFees.Code, VendorFees.CheckNumber, VendorFees.Subtotal
FROM VendorFees INNER JOIN
VendorLicense ON VendorFees.VendorLicNumber = VendorLicense.VendorLicNumber
WHERE (@Start_Date is null or VendorFees.[Date] >= @Start_Date)
or(@End_Date is null or VendorFees.[Date] <= @End_Date)


ORDER BY VendorLicense.VendorName
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2008-11-03 : 19:36:56
Let's do this slowly:

WHERE VendorFees.[Date] >= @Start_Date

Does that return rows? If so, move to the next:

WHERE VendorFees.[Date] <= @End_Date

...

WHERE VendorFees.[Date] >= @Start_Date AND VendorFees.[Date] <= @End_Date

...


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

Subscribe to my blog
Go to Top of Page

PeterNeo
Constraint Violating Yak Guru

357 Posts

Posted - 2008-11-03 : 23:03:51
change u r WHERE condition to

WHERE (@Start_Date is null or DATEADD(DAY, DATEDIFF(DAY, 0, VendorFees.[Date]), 0) >= @Start_Date)
or(@End_Date is null or DATEADD(DAY, DATEDIFF(DAY, 0, VendorFees.[Date]), 0) <= @End_Date)


"There is only one difference between a dream and an aim. A dream requires soundless sleep to see, whereas an aim requires sleepless efforts to achieve..!!"
Go to Top of Page

muzzettemm
Posting Yak Master

212 Posts

Posted - 2008-11-04 : 12:05:15
Thank you PeterNeo that did the trick
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-11-04 : 12:08:23
quote:
Originally posted by muzzettemm

Thank you PeterNeo that did the trick


should nt it be and rather than or between two conditions?
Go to Top of Page

muzzettemm
Posting Yak Master

212 Posts

Posted - 2008-11-04 : 12:37:07
I put the AND in works great
Go to Top of Page
   

- Advertisement -