Combine Date and Time fields in SQL Server into one column?

SQL Server 101
SQL Server 101
6.8 هزار بار بازدید - 2 سال پیش - You cannot just add Date
You cannot just add Date and Time fields together in SQL Server, as you do in Excel. So how do you do it?
My SQL Server Udemy courses are:
70-461, 70-761 Querying Microsoft SQL Server with T-SQL: https://rebrand.ly/querying-microsoft...
98-364: Database Fundamentals (Microsoft SQL Server): https://rebrand.ly/database-fundamentals
70-462 SQL Server Database Administration (DBA): https://rebrand.ly/sql-server-dba
Microsoft SQL Server Reporting Services (SSRS): https://rebrand.ly/sql-server-ssrs
SQL Server Integration Services (SSIS): https://rebrand.ly/sql-server-ssis
SQL Server Analysis Services (SSAS): https://rebrand.ly/sql-server-ssas-mdx
Microsoft Power Pivot (Excel) and SSAS (Tabular DAX model): https://rebrand.ly/microsoft-powerpiv...
----
In Excel, you can combine Date and Time together by using the + . However, you cannot do this in SQL Server:
SELECT @Dat + @Tim
This results in an error.
In this video, we'll look at how to CAST or CONVERT the values into datetime, and then we can use the + operator to add them together.
However, what if you want to have it as a DateTime2? You cannot use the + operator then. Instead, you can use CAST (or CONVERT), DATEDIFF and DATEADD.
In this video, we'll see how you can do both of these options.
If you would like to do this as a Practice Activity, then here is the code to start with:
declare @Dat as date = '2024-01-31'
declare @Tim as time = '17:14:00'
2 سال پیش در تاریخ 1401/02/01 منتشر شده است.
6,899 بـار بازدید شده
... بیشتر