Wrox Programmer Forums
|
SQL Server 2000 General discussion of Microsoft SQL Server -- for topics that don't fit in one of the more specific SQL Server forums. version 2000 only. There's a new forum for SQL Server 2005.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the SQL Server 2000 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 August 2nd, 2005, 12:28 PM
Authorized User
 
Join Date: Aug 2004
Posts: 38
Thanks: 0
Thanked 0 Times in 0 Posts
Default If already Exsists

Hi GUYS HOWS LIFE GOING..PAT, BRETT, how are you two doing???

I have a question and btw the other issues have been either resolved or no longer necessary.

Anyways I have this Stored Procedure that will insert updates into a form for me but the problem is if the records (example records between the date of 1/1/05 and 12/31/05) but the problem is if the 05 are already in there and I find that there's more 05's I get an primary key message, and I need to have it skip over those 05 that are already in the database adn insert the ones that are not already in there

Code:
ALTER PROCEDURE Corvan_05Insert
   @pdBegin  DATETIME =  NULL
,  @pdEnd    DATETIME=   NULL
AS

IF @pdBegin NOT BETWEEN '2005-01-01' AND '2005-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 September 7th, 2005, 08:41 PM
Friend of Wrox
 
Join Date: Aug 2004
Posts: 385
Thanks: 0
Thanked 0 Times in 0 Posts
Default

You could find the max date value in your target table and use that for the @pdBegin date if I understand your question.










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