SQL to find the year (1 Viewer)

Joy83

Member
Local time
Today, 09:31
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:

Velocity

New member
Local time
Today, 22:01
Joined
Nov 8, 2022
Messages
7
Code:
SELECT SUM(cost) as total_cost
FROM your_table
WHERE date LIKE '%2011%'
 

ebs17

Well-known member
Local time
Today, 18:31
Joined
Feb 7, 2020
Messages
1,946
SQL:
SELECT
   your_Date \ 100 AS [year],
   SUM(cost) AS total_cost
FROM
   your_table
GROUP BY
   your_Date \ 100
 

sonic8

AWF VIP
Local time
Today, 18:31
Joined
Oct 27, 2015
Messages
998
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.
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 12:31
Joined
Feb 19, 2002
Messages
43,275
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

Top Bottom