SQL: how to extract the month from a date time field

sql, sql-server

Solution

Use MONTH()

UPDATE your_table
SET some_column = MONTH(date_column)
WHERE some_column IS NULL

Problem

I need to to extract the month from date time fieldA then put the result into fieldB as an integer in the same table IF fieldB is empty. eg) `1988-02-03 00:00:00.000` I need to extract 02 and put the result into another field only if that field is empty. I guess this will end up as a stored procedure.

Original source

Related problems