| |

VerySource

 Forgot password?
 Register
Search
View: 827|Reply: 6

Solve a SQL statement

[Copy link]

4

Threads

6

Posts

6.00

Credits

Newbie

Rank: 1

Credits
6.00

 China

Post time: 2020-2-20 20:30:01
| Show all posts |Read mode
I calculated the data of the previous month this month, and I want to get the month automatically as MONTH (DATE) -1, but if I encounter January, it will be difficult to handle. How can I write such a SQL statement? Or is there any other way to solve it?
Reply

Use magic Report

0

Threads

4

Posts

5.00

Credits

Newbie

Rank: 1

Credits
5.00

 China

Post time: 2020-4-29 19:45:01
| Show all posts
Subtract 30 days from the current date, then take the month
Reply

Use magic Report

0

Threads

9

Posts

9.00

Credits

Newbie

Rank: 1

Credits
9.00

 China

Post time: 2020-4-30 21:00:01
| Show all posts
d = Month (DateAdd ("m", -1, Date))
Reply

Use magic Report

4

Threads

6

Posts

6.00

Credits

Newbie

Rank: 1

Credits
6.00

 China

 Author| Post time: 2020-5-5 20:00:01
| Show all posts
But how does the year differ, please be specific, thank you!
Reply

Use magic Report

0

Threads

6

Posts

6.00

Credits

Newbie

Rank: 1

Credits
6.00

 Invalid IP Address

Post time: 2020-5-8 23:15:01
| Show all posts
IntMonth = IIf (Month (Date) = 1, 12, Month (Date)-1)
IntYear = IIf (IntMonth> Month (Date), Year (Date)-1, Year (Date))
Reply

Use magic Report

0

Threads

6

Posts

6.00

Credits

Newbie

Rank: 1

Credits
6.00

 Invalid IP Address

Post time: 2020-5-9 17:15:01
| Show all posts
I read it wrong and asked SQL statement. Khan ~~~
Reply

Use magic Report

0

Threads

9

Posts

9.00

Credits

Newbie

Rank: 1

Credits
9.00

 China

Post time: 2020-5-17 14:00:01
| Show all posts
If the format containing the year and month is yyyy-mm then:

The SQL database can:
convert (varchar (7), dateadd (month, -1, getdate ()), 120)

access can:
Format (DateAdd ("m", -1, Date), "yyyy-mm")
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list