Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Database > SQL Language
|
SQL Language SQL Language discussions not specific to a particular RDBMS program or vendor.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the SQL Language section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old October 31st, 2005, 02:24 PM
Authorized User
 
Join Date: Aug 2004
Posts: 38
Thanks: 0
Thanked 0 Times in 0 Posts
Default Help On Stored Procedure

I have a stored procedure that inserts data from one table to another when I press the command button in Access 2003. Now the procedure is that when physical files go to storage the records go to the storage database called Corovan. So it takes database from the Termination Database to the corovan Database. The problem is it does it by dates so if some 2005 are already in the corovan database and I try to enter in more through the stored procedure I get a primary key error message. What I need to add to the stored procedure is a command that will only add the info that isnt already in the database 2005 or not without breaking any primary key rules, does that make sense???




ALTER PROCEDURE Corvan_Insertsp
   @pdBegin DATETIME = NULL
, @pdEnd DATETIME= NULL
AS

IF @pdBegin NOT BETWEEN '2003-01-01' AND '2003-12-31' -- "bad" begin date
   SET @pdBegin = DateAdd(year, -2, GetDate()) -- Back up two years

IF @pdEnd IS NULL -- If no end date
   SET @pdEnd = DateAdd(year, 1, @pdBegin) -- One year after the begin date

INSERT INTO [GamingCommissiondb].[dbo].[Corovan_Table](
[TM #], [FirstName], [LastName]
,[SS #], [TerminationDate], [Voluntary or Involuntary]
)SELECT
[TM #],[FirstName],[LastName]
,[SocialSecurityNumber], [TerminationDate], [VoluntaryorInvoluntary]
FROM TERMINATION
WHERE TerminationDate BETWEEN @pdBegin AND @pdEnd
RETURN


 
Old October 31st, 2005, 02:30 PM
Authorized User
 
Join Date: Sep 2005
Posts: 95
Thanks: 0
Thanked 0 Times in 0 Posts
Default

INSERT INTO [GamingCommissiondb].[dbo].[Corovan_Table](
[TM #], [FirstName], [LastName]
,[SS #], [TerminationDate], [Voluntary or Involuntary]
)SELECT
t.[TM #],t.[FirstName],t.[LastName]
,t.[SocialSecurityNumber], t.[TerminationDate], t.[VoluntaryorInvoluntary]
FROM TERMINATION t
left join [GamingCommissiondb].[dbo].[Corovan_Table] c on t.[TM #] = c.[TM #]
WHERE t.TerminationDate BETWEEN @pdBegin AND @pdEnd
and c.[TM #] is null

“I sense many useless updates in you... Useless updates lead to fragmentation... Fragmentation leads to downtime...Downtime leads to suffering..Fragmentation is the path to the darkside.. DBCC INDEXDEFRAG and DBCC DBREINDEX are the force...May the force be with you" -- http://sqlservercode.blogspot.com/
 
Old October 31st, 2005, 07:11 PM
Authorized User
 
Join Date: Aug 2004
Posts: 38
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I tried that and this is the message I get


Line 9: Incorrect syntax near '@pdBegin'.






Similar Threads
Thread Thread Starter Forum Replies Last Post
stored procedure prashant_telkar SQL Server 2000 1 July 9th, 2007 07:57 AM
Stored Procedure jezywrap SQL Server ASP 1 January 3rd, 2007 12:29 AM
stored procedure kdm260 SQL Server 2000 2 June 19th, 2006 04:45 PM
Stored Procedure rajanikrishna SQL Server 2000 0 July 18th, 2005 05:01 AM
Help About Stored Procedure zhuge6 BOOK: ASP.NET Website Programming Problem-Design-Solution 3 May 20th, 2005 09:27 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.