Solved

Need some help with DATEPART DATEDIFF

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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Determine next b-weekly date 12 53
ASP SQL Syntax Duplicate Key 7 66
Complex SQL 10 33
Convert int to military time 8 20
JSON is being used more and more, besides XML, and you surely wanted to parse the data out into SQL instead of doing it in some Javascript. The below function in SQL Server can do the job for you, returning a quick table with the parsed data.
Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
Via a live example, show how to setup several different housekeeping processes for a SQL Server.
Viewers will learn how the fundamental information of how to create a table.

708 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now