Solved

Need some help with DATEPART DATEDIFF

Posted on 2013-05-23
4
371 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 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

Turn Insights into Action

Communication across every corner of your business is essential to increase the velocity of your application delivery and support pipeline. Automate, standardize, and contextualize your communication processes with xMatters.

Question has a verified solution.

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

Introduction In my previous article (http://www.experts-exchange.com/Microsoft/Development/MS-SQL-Server/SSIS/A_9150-Loading-XML-Using-SSIS.html) I showed you how the XML Source component can be used to load XML files into a SQL Server database, us…
In this article we will learn how to fix  “Cannot install SQL Server 2014 Service Pack 2: Unable to install windows installer msi file” error ?
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.
Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…

719 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