Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

MS SQL (Stored?) Query help

Status
Not open for further replies.

ksaab2002

MIS
Jan 6, 2005
66
0
0
US
HI, I really do!

I need to link two tables dbo.Survey and dbo.CheckSurveyed on dbo.Survey.Full_Name to dbo.CheckSurveyed.Pass_Name

Then I need to:
update dbo.Survey.SurveyDate to dbo.CheckSurveyed.SurveyDate

Where dbo.CheckSurveyed.SurveyDate is (Greater than 6 Months prior to) dbo.Survey.Load_Date

I am lost when it comes to transact SQL syntax! I am struggling writing the query...

Also, I will need to run this query often as a call from a website? Can it/ should it be done as a stored procedure and if so, how would I embed it in one?

Thanks!!
 
Code:
CREATE Procedure UpdateSurvey
AS
BEGIN
   UPDATE dbo.Survey
          SET SurveyDate to dbo.CheckSurveyed.SurveyDate
   FROM Survey
   INNER JOIN CheckSurveyed ON 
         dbo.Survey.Full_Name = dbo.CheckSurveyed.Pass_Name
   WHERE DateDiff(month,  dbo.CheckSurveyed.SurveyDate,
                          dbo.Survey.Load_Date) > 6
(not tested)



END

Borislav Borissov
VFP9 SP1, SQL Server 2000/2005.
 
I changed "SET SurveyDate to dbo.CheckSurveyed.SurveyDate" to "SET SurveyDate = dbo.CheckSurveyed.SurveyDate"

After I got an error ....ner "to"

Also, I am getting "Incorrect syntax near '6'"

Any ideas? Many thanks!!
 
Oops, You correct change TO to equal sigh, also you must put

END at the end :)
Code:
CREATE Procedure UpdateSurvey
AS
BEGIN
   UPDATE dbo.Survey
          SET SurveyDate = dbo.CheckSurveyed.SurveyDate
   FROM Survey
   INNER JOIN CheckSurveyed ON
         dbo.Survey.Full_Name = dbo.CheckSurveyed.Pass_Name
   WHERE DateDiff(month,  dbo.CheckSurveyed.SurveyDate,
                          dbo.Survey.Load_Date) > 6
END

Borislav Borissov
VFP9 SP1, SQL Server 2000/2005.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top