SQL to find the year

Joy83

Member
Local time
Today, 12:32
Joined
Jan 9, 2020
Messages
116
Hello,
I have a field that contains the date in this format 201109 integer
Each row includes cost and that field
I want to build sql that gets me the the amounts by year?
 
Last edited:
Code:
SELECT SUM(cost) as total_cost
FROM your_table
WHERE date LIKE '%2011%'
 
SQL:
SELECT
   your_Date \ 100 AS [year],
   SUM(cost) AS total_cost
FROM
   your_table
GROUP BY
   your_Date \ 100
 
I have a field that contains the date in this format 201109 integer
You should explain the format.
Without further explanation, the year could be 2020, 2011, or 2009 to name just the most plausible.
 
What ever this format actually is, it is far better to keep dates as date type data types. If this is yyyymm, then just use the first day of the month to make a valid date. You can show whatever you want on your forms/reports.
 

Users who are viewing this thread

Back
Top Bottom