Solved

Need some help with DATEPART DATEDIFF

Posted on 2013-05-23
4
361 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 48

Accepted Solution

by:
PortletPaul earned 500 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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

Introduction SQL Server Integration Services can read XML files, that’s known by every BI developer.  (If you didn’t, don’t worry, I’m aiming this article at newcomers as well.) But how far can you go?  When does the XML Source component become …
Why is this different from all of the other step by step guides?  Because I make a living as a DBA and not as a writer and I lived through this experience. Defining the name: When I talk to people they say different names on this subject stuff l…
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
Via a live example, show how to setup several different housekeeping processes for a SQL Server.

856 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