How to extract part of a number in Microsoft SQL Server, and how to convert it into a date

preview_player
Показать описание
How do you get just part of a number? What if it were a string?
My SQL Server Udemy courses are:
----
Let's suppose that you have a number which represents a year and a month - for example:
DECLARE @Field INT = 202306
How could you extract the 2023 (year) and the 6 (month) separately?
Would it be any different if you had:
DECLARE @Field DECIMAL(8,2) = 202306
What about if you had?
DECLARE @Field VARCHAR(10) = '202306'
Finally, what if you wanted to turn it into a date?
Рекомендации по теме
Комментарии
Автор

Great explanation ! I have a question how can we separate this ( 2023/03/17 15:00:00 GMT) into different columns.

ToonsHubHindi
Автор

Hey there, glad to meet again.
I learned about timestamp as a date data type.
My question is, if i where to record timestamps of every record entered into the database. Would the sql server generate two identical timestamps given the records where run simultaneously..is that case a hypothetical one or would it happen?
Thanks for taking care of this.

hasanmougharbel