Solved

Need some help with DATEPART DATEDIFF

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

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

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

Having an SQL database can be a big investment for a small company. Hardware, setup and of course, the price of software all add up to a big bill that some companies may not be able to absorb.  Luckily, there is a free version SQL Express, but does …
Let's review the features of new SQL Server 2012 (Denali CTP3). It listed as below: PERCENT_RANK(): PERCENT_RANK() function will returns the percentage value of rank of the values among its group. PERCENT_RANK() function value always in be…
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function

777 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