MS SQL Getdate() Adding default date

Hello everyone im currently experiencing difficulty’s with One of my tasks any help would be greatly appreciated ive been stuck on this for 1 hour.

Create a stored procedure called Task35 that creates a calculated field named “Order Date”
for the Products table. Include necessary SQL statements in the query to specify the current
date as the Order Date for each of the products in the table. The query should display the
Product Name along with the Order Date of each product.

My current MS SQL code is:
ALTER PROCEDURE [dbo].[Task35]
AS
ALTER TABLE Products
ADD [orderdate] SMALLDATETIME DEFAULT GETDATE()
SELECT ProductName,orderdate
FROM Products

Thank you for taking the time to read this
-Ryfizzle

I don’t understand this… If it is a calculated field, why do you add it to the table?

i needed to alter table to insert a new column
with this code that i have right now im currently getting everything showing up right except the date.

You said a calculated field. A calculated field does not exist in the table, you create it on the fly in your query

1 Like

thanks Molona i was thinking about it in a completely wrong way.

ALTER PROCEDURE Task35
AS
SELECT ProductName , GETDATE() AS Orderdate
FROM Products

what i was doing wrong was thinking of it as adding a new column , ive posted the ms-sql code into here so if anyone has trouble with a similar thing they can benefit from it.

1 Like

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.