I'm having trouble figuring out how to use a dynamic SQL Server query to change the datetime fields in my database, called OnlineStore, to be random and in the current year.
It should be noted that this relates to homework. My class is fairly unstructured, so I'm having a hard time knowing where to go from here.
My question is: How can I write a dynamic SQL Server query that may use loops or table variables and takes the 2 datetime columns in my database (Product.LastOrderDate, Orders.OrderDate) and assigns each row a random date in the current year?
This is what I have so far. I'm open to any changes.
Declare @SQL varchar(max) = '
Declare @D1 float = cast(cast(''2017-01-01 00:00:00'' as datetime) as float);
Declare @D2 float = cast(cast(''2017-12-31 23:59:59'' as datetime) as float);