December 17, 2008 at 12:36 pm
Hello everyone, I am new here so i hope im not stepping on any toes, i am looking to make an update query that i can run upon the import of a new set of data. from there i will join it to another table to build an organizational hierarchy. Unfortunately i dont have key that will work with both tables due to there being historical data to take into account.
the simple part of this question would be an update statement that i would like to write that would add a column with a variable date depending on when i upload the data.
update dbo.[PS - daily Temp]
set [report Date] = @report as smalldatetime
Where Report Date is null
so when i run this of course errors out, could someone assist me with the correct syntax to be able to add so the statement will prompt me with a dialog box to input the column data which is a date?
December 17, 2008 at 1:15 pm
Not this?
declare @report smalldatetime
select @report = getdate()
update dbo.[PS - daily Temp]
set [report Date] = @report
Where [Report Date] is null
December 17, 2008 at 1:25 pm
Almost perfect! thanks! except that will provide the time right now. I was trying to avoid this as i am always working with the prior day, and sometimes i will not be able to update the data daily immeditately, so i may get anywhere up to a week behind on the import.
What i was really looking for was to be prompted to enter the date prior to writing the data to the table.
December 17, 2008 at 1:44 pm
SSMS will not prompt you for a parameter like that. You need to modify this yourself every time you run the script.
You can use the DATEADD function to get a date from yesterday, as in:
DATEADD(day, -1, getdate()) -- yesterday at this time
Now, if you don't want to include the time:
DATEADD(day, DATEDIFF(day, 0, getdate()) - 1, 0) -- yesterday's date, 00:00:00.000 time
Jeffrey Williams
“We are all faced with a series of great opportunities brilliantly disguised as impossible situations.”
― Charles R. Swindoll
How to post questions to get better answers faster
Managing Transaction Logs
December 17, 2008 at 1:57 pm
Ughhh... I was afraid that would be the answer...
Thanks for the assistance! 🙂 it is much appreciated.
December 17, 2008 at 4:32 pm
DOS batch job with a VB Script to popup an input window. Either that, or a "control" table that will remember the last run date.
--Jeff Moden
Change is inevitable... Change for the better is not.
Viewing 6 posts - 1 through 5 (of 5 total)
You must be logged in to reply to this topic. Login to reply