Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
Stuey
Starting Member
2 Posts |
Posted - 2014-09-09 : 07:18:34
|
I am aware that some are against the 'Homework' style requests and its understandable, and I am not asking for a solution just some guidance as I am stuck completely as the task that has been asked seems to me as not possible since it conflicts or its because i been working on this assignment for the last 5 hours and my brain has reverted to retard mode.I was asked to create a calculated field named Order Date for my Products Table that specifies the current date as the Order Date for each product in the table. Should display Products Name and Order Name. The issue i see is its asking me to use the GETDATE Function which is a expression not a aggregate so not sure how i can get the needed results. I was thinking of the below as the best methods just not quite sure and wished some extra feedback from others.Would this query be best to be done using a subquery? Would this allow both the aggregate and scalar functions to play nicely?As there is no actual Order Date field in the products table i am only assuming it is asking me to return the current system time as the order date which would mean i have to use the GETDATE clause.Any guidance would be appreciated I rather not the answer given as i do not believe I will learn if hand fed answers but its difficult to get the help at times from teachers they seem to refer back to pages in the material given that does not really explain it well enough for me to understand completely. Having a learning disability does not make it any easier at times. Thanks in advance. |
|
gbritton
Master Smack Fu Yak Hacker
2780 Posts |
Posted - 2014-09-09 : 07:45:47
|
In your CREATE TABLE, for the column [Order Date] specify DEFAULT GETDATE()See here for more examples: http://www.w3schools.com/sql/sql_default.asp |
|
|
Stuey
Starting Member
2 Posts |
Posted - 2014-09-10 : 02:41:01
|
quote: Originally posted by gbritton In your CREATE TABLE, for the column [Order Date] specify DEFAULT GETDATE()See here for more examples: http://www.w3schools.com/sql/sql_default.asp
Thanks for that it did lead me in the right direction but the table was already created and I was not after altering the table at all just displaying the current system time next to each product.After stepping away for a while and relooking at the different GETDATE stuff i managed to get it right the way i needed it. BElow is what i used CREATE PROCEDURE Task35ASSELECT GETDATE () AS [Order Date], [Product Name]FROM ProductsGROUP BY [Product Name] |
|
|
|
|
|