?
Solved

Need some help with DATEPART DATEDIFF

Posted on 2013-05-23
4
Medium Priority
?
383 Views
Last Modified: 2013-05-23
sql.Format("SELECT DATEPART(year,A.Lieferscheindatum)AS year,\
                                 DATEPART(month,A.Lieferscheindatum)AS month,\
                                 SUM(B.Einheitbez13wert)AS Gewicht\
                                 FROM Lieferscheine AS A , Lieferscheinpositionen AS B\
                                 WHERE A.LieferscheinNr=B.LieferscheinNr AND A.LieferscheinNr<200000\
                                 GROUP BY DATEPART(month,A.Lieferscheindatum),\
                               DATEPART(year,A.Lieferscheindatum)\
                               ORDER by DATEPART(year,A.Lieferscheindatum)ASC,\
                               DATEPART(month,A.Lieferscheindatum)ASC");

Hello,
I just want to get values of my SQL Table starting May 2006 till today.
How can I do this, please help.
Thank you.
Best regards,
Thomas
0
Comment
Question by:tsp2002
  • 2
4 Comments
 
LVL 22

Expert Comment

by:Om Prakash
ID: 39190681
Try:
select * from table_name where your_date_field >= '5/1/2006'
0
 

Author Comment

by:tsp2002
ID: 39190730
sql.Format("SELECT DATEPART(year,A.Lieferscheindatum)AS year,\
                                 DATEPART(month,A.Lieferscheindatum)AS month,\
                                 SUM(B.Einheitbez13wert)AS Gewicht\
                                 FROM Lieferscheine AS A , Lieferscheinpositionen AS B\
                                 WHERE A.LieferscheinNr=B.LieferscheinNr AND A.LieferscheinNr<200000\
AND WHERE A.LIeferscheindatum>='1.5.2006'\
                                 GROUP BY DATEPART(month,A.Lieferscheindatum),\
                               DATEPART(year,A.Lieferscheindatum)\
                               ORDER by DATEPART(year,A.Lieferscheindatum)ASC,\
                               DATEPART(month,A.Lieferscheindatum)ASC");


Will not work error
0
 
LVL 49

Accepted Solution

by:
PortletPaul earned 2000 total points
ID: 39190888
SELECT
      DATEPART(year, A.Lieferscheindatum) AS year_pt
    , DATEPART(month, A.Lieferscheindatum) AS month_pt
    , SUM(B.Einheitbez13wert) AS Gewicht
FROM Lieferscheine AS A
INNER JOIN Lieferscheinpositionen AS B ON A.LieferscheinNr = B.LieferscheinNr
WHERE A.LieferscheinNr < 200000
AND A.Lieferscheindatum >= '2013-05-01'
GROUP BY
      DATEPART(month, A.Lieferscheindatum)
    , DATEPART(year, A.Lieferscheindatum)
ORDER BY
      DATEPART(year, A.Lieferscheindatum) ASC
    , DATEPART(month, A.Lieferscheindatum) ASC

Open in new window

(+edit, sorry)
don't use field or aliases like 'year' or 'month' they are reserved words
0
 

Author Closing Comment

by:tsp2002
ID: 39193435
thank you ..... very much that will work
Best regards,
Thomas
0

Featured Post

Get free NFR key for Veeam Availability Suite 9.5

Veeam is happy to provide a free NFR license (1 year, 2 sockets) to all certified IT Pros. The license allows for the non-production use of Veeam Availability Suite v9.5 in your home lab, without any feature limitations. It works for both VMware and Hyper-V environments

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In the first part of this tutorial we will cover the prerequisites for installing SQL Server vNext on Linux.
MSSQL DB-maintenance also needs implementation of multiple activities. However, unprecedented errors can hamper the database management. In that case, deploying Stellar SQL Database Toolkit ensures fast and accurate database and backup repair as wel…
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.
Suggested Courses

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question