SQL query - datepart ?

SQL query - datepart ?

Post by philip » Tue, 11 Mar 2003 23:38:52



I have a query that will display data based on a
particular month chosen by the end user from a combo box.
My query does not return the correct data when the user
selects January it also returns October, November and
December. I also tried using the "m" instead of "mm" in
the datepart function. Below is my query. Any help is
appreciated.

PhilipL


AS

SELECT          DailySalesTotal,Location,StoreName
FROM            dbo.Sales


+ '%'

+'%'  
ORDER BY        DailySalesTotal DESC

 
 
 

SQL query - datepart ?

Post by Uri Diman » Tue, 11 Mar 2003 23:45:59


Philip
Please post DDL and some INSERT's data that people don't have to guess.
What is expected result?


> I have a query that will display data based on a
> particular month chosen by the end user from a combo box.
> My query does not return the correct data when the user
> selects January it also returns October, November and
> December. I also tried using the "m" instead of "mm" in
> the datepart function. Below is my query. Any help is
> appreciated.

> PhilipL

> CREATE PROCEDURE [SalesData_Get]

> AS

> SELECT          DailySalesTotal,Location,StoreName
> FROM            dbo.Sales


> + '%'

> +'%'
> ORDER BY        DailySalesTotal DESC


 
 
 

SQL query - datepart ?

Post by Rob Williscrof » Tue, 11 Mar 2003 23:55:16



> I have a query that will display data based on a
> particular month chosen by the end user from a combo box.
> My query does not return the correct data when the user
> selects January it also returns October, November and
> December. I also tried using the "m" instead of "mm" in
> the datepart function. Below is my query. Any help is
> appreciated.

> PhilipL

> CREATE PROCEDURE [SalesData_Get]

> AS

> SELECT          DailySalesTotal,Location,StoreName
> FROM            dbo.Sales


> + '%'

> +'%'  
> ORDER BY        DailySalesTotal DESC

All of (1, 10, 11, 12) are LIKE '1%'

try:


HTH

Rob.

 
 
 

SQL query - datepart ?

Post by Philip » Wed, 12 Mar 2003 05:28:30


Quote:>All of (1, 10, 11, 12) are LIKE '1%'

>try:

> AND           CAST(DATEPART(mm,DailySalesTotal) AS


Quote:

>HTH

>Rob.
>.

Thanks for your response but I have a combo box that
displays all the months "January, February, ...and <all> "
(13 items in the combo box). So I need the LIKE clause to
trap the "<all>" if the user selects "<all>" then data for
the year will be displayed and if they select a month only
that month`s data
etc.

PhilpL

 
 
 

SQL query - datepart ?

Post by Tom Morea » Wed, 12 Mar 2003 05:36:14


Really, you should have the front end make the decision to call one stored proc for the <all> case and another stored proc for an individual month.  You'd be getting better performance, since each proc would be optimized for the individual query.

--
Tom

---------------------------------------------------------------
Thomas A. Moreau, BSc, PhD, MCSE, MCDBA
SQL Server MVP
Columnist, SQL Server Professional

www.pinnaclepublishing.com/sql


  >All of (1, 10, 11, 12) are LIKE '1%'
  >
  >try:
  >
  > AND           CAST(DATEPART(mm,DailySalesTotal) AS

  >
  >
  >HTH
  >
  >Rob.
  >.
  >

  Thanks for your response but I have a combo box that
  displays all the months "January, February, ...and <all> "
  (13 items in the combo box). So I need the LIKE clause to
  trap the "<all>" if the user selects "<all>" then data for
  the year will be displayed and if they select a month only
  that month`s data
  etc.

  PhilpL

 
 
 

1. DatePart SQL Query issue

Hi,

I'm writing a stored procedure.
In the procedure, I have a datetime as below





I can't figure out how to properly use datepart (is that
the right function anyways???) to split the big date into
the time and date.

Any help is greatly appreciated.

Thanks,
Brad Wyatt

2. The HiTek Report 2/20

3. Using DatePart and DateDiff together in a query

4. ADO Recordset Timeout

5. Datepart Query - Please Help!

6. Package Error : Parameter is incorrect.

7. Where DatePart Query

8. using MS ASP to Oracle OLE object on 7.3

9. DATEPART problems with SQL server

10. Problem with function datepart() in SQL 6.5

11. Use of the DATEPART Function in SQL

12. T-SQL DATEPART function

13. T-SQL DatePart Func