| 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 ONGOSET QUOTED_IDENTIFIER ONGOALTER PROCEDURE [dbo].[SearchVendor_Fees]@Start_Date DATETIME = NULL,@End_Date DATETIME = NULL,@Enter_VendorName NVARCHAR(255)ASSELECT VendorLicense.VendorName, VendorLicense.VendorLicNumber, VendorFees.DebitAmount, VendorFees.CreditAmount, VendorFees.Date, VendorFees.CheckNumber, VendorFees.SubtotalFROM VendorFees INNER JOIN VendorLicense ON VendorFees.VendorLicNumber = VendorLicense.VendorLicNumberWHERE (@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 |
|
|
muzzettemm
Posting Yak Master
212 Posts |
Posted - 2008-11-03 : 19:08:57
|
| I tried that and for some reason it didnt work |
 |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
|
|
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 ONGOSET QUOTED_IDENTIFIER ONGOALTER PROCEDURE [dbo].[VendorFee_Totals]@Start_Date DATETIME = NULL,@End_Date DATETIME = NULLASSELECT VendorLicense.VendorName, VendorLicense.LicenseIssueDate, VendorLicense.VendorLicNumber, VendorFees.DebitAmount, VendorFees.CreditAmount, VendorFees.Date, VendorFees.Code, VendorFees.CheckNumber, VendorFees.SubtotalFROM VendorFees INNER JOIN VendorLicense ON VendorFees.VendorLicNumber = VendorLicense.VendorLicNumberWHERE (@Start_Date is null or VendorFees.[Date] >= @Start_Date) or(@End_Date is null or VendorFees.[Date] <= @End_Date)ORDER BY VendorLicense.VendorName |
 |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
|
|
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..!!" |
 |
|
|
muzzettemm
Posting Yak Master
212 Posts |
Posted - 2008-11-04 : 12:05:15
|
| Thank you PeterNeo that did the trick |
 |
|
|
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? |
 |
|
|
muzzettemm
Posting Yak Master
212 Posts |
Posted - 2008-11-04 : 12:37:07
|
| I put the AND in works great |
 |
|
|
|