英文:
Insert a DATETIME value with only MONTH and YEAR
问题
我在SQL Server中编写存储过程,需要使用输入的MONTH和YEAR插入DATETIME列的值。
示例:输入MONTH = 7,YEAR = 2023,结果为:
| DATETIME |
|---|
| 2023-07-01 00:00:00.000 |
在插入新记录时,DAY值为01。
英文:
I'm writing a stored procedure in SQL Server and I need to insert a value into DATETIME column with input of MONTH and YEAR.
Example: Input MONTH = 7, YEAR = 2023, the result is:
| DATETIME |
|---|
| 2023-07-01 00:00:00.000 |
The DAY value is 01 when insert new record.
答案1
得分: 2
使用函数 DATEFROMPARTS(@Year, @Month, 1),我得到了答案。
英文:
I got the answer. Use function DATEFROMPARTS(@Year, @Month, 1)
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。


评论