?
Solved

Timestamp when inserting records into a table

Posted on 2006-04-25
2
Medium Priority
?
194 Views
Last Modified: 2010-03-19
I have a query that inserts records into a table (FRA) and now want to add the time that is inserted into the FRA table to the record.  Any ideas?

This is what I tried, but it doesn't work:


INSERT INTO FRA

declare @cur_date as datetime
set @cur_date = getdate()

select      @cur_date as 'DATEPOSTED',cubeproj.PROJ_NAME as 'PROJECTNAME',CPN.PROJ_OUTLINECODE_NAME as 'CAPITALPROJECT#',projent.ProjectEnterpriseText3 as 'DESCRIPTION',
     PM.Proj_Outlinecode_name as 'PROJECTMANAGER',projent.ProjectEnterpriseText14 as 'BUDGET VARIANCE EXPLANATION',
     projent.ProjectEnterpriseText15 as 'SCHEDULE VARIANCE EXPLANATION',projent.ProjectEnterpriseText7 as 'AREAS_OF_CONCERN',
     projent.ProjectEnterpriseText4 as 'Explanation'

from      MSP_CUBE_PROJECTS cubeproj left outer join
     MSP_CUBE_ENTERPRISE_PROJECT_OUTLINE_1 CPN on cubeproj.ENTERPRISE_PROJECT_CODE1 = CPN.PROJ_OUTLINECODE_ID left outer join
     MSP_CUBE_ENTERPRISE_PROJECT_OUTLINE_16 PM on cubeproj.ENTERPRISE_PROJECT_CODE16 = PM.PROJ_OUTLINECODE_ID left outer join
     MSP_VIEW_PROJ_PROJECTS_ENT projent on cubeproj.proj_uid = projent.ent_projectuniqueid
 
where ENTERPRISE_PROJECT_CODE10 = 91

This is the error message I get:Server: Msg 156, Level 15, State 1, Line 3
Incorrect syntax near the keyword 'declare'.
0
Comment
Question by:fusionfx2000
  • 2
2 Comments
 
LVL 33

Expert Comment

by:knightEknight
ID: 16537127
put the insert statement under the declare:

declare @cur_date as datetime
set @cur_date = getdate()

INSERT INTO FRA

0
 
LVL 33

Accepted Solution

by:
knightEknight earned 150 total points
ID: 16537140
or skip the declare altogether and just do this:

select      getdate() as 'DATEPOSTED'  ...
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Recently we ran in to an issue while running some SQL jobs where we were trying to process the cubes.  We got an error saying failure stating 'NT SERVICE\SQLSERVERAGENT does not have access to Analysis Services. So this is a way to automate that wit…
This month, Experts Exchange sat down with resident SQL expert, Jim Horn, for an in-depth look into the makings of a successful career in SQL.
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties
Via a live example, show how to setup several different housekeeping processes for a SQL Server.
Suggested Courses

749 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question