troubleshooting Question

SQL Stored Procedure: Insert / Update based on certain criteria

Avatar of CEGE
CEGEFlag for Spain asked on
DatabasesMicrosoft SQL ServerMicrosoft SQL Server 2005
12 Comments3 Solutions293 ViewsLast Modified:
Hello:

I have a table called PreferenciasCliente with the following fields.
      [CodigoCliente] [char] (10) COLLATE Modern_Spanish_CI_AS NULL ,
      [IdiomaCAT] [bit] NULL ,
      [IdiomaCAST] [bit] NULL ,
      [IdiomaFR] [bit] NULL ,
      [IdiomaENG] [bit] NULL ,
      [PaletUE] [bit] NULL ,
      [PaletUEInt] [bit] NULL ,
      [MasterColor] [varchar] (50) COLLATE Modern_Spanish_CI_AS NULL ,
      [Impresion] [varchar] (50) COLLATE Modern_Spanish_CI_AS NULL ,
      [Etiquetas] [varchar] (50) COLLATE Modern_Spanish_CI_AS NULL ,
      [ContEtiq] [text] COLLATE Modern_Spanish_CI_AS NULL ,
      [EspecEst] [text] COLLATE Modern_Spanish_CI_AS NULL

WHat I then have is two processes that interact with a single table. Right now, one deletes a record if [CodigoCliente] exists, if not it creates a new record. If it already exists, it gets overwritten. I now have another process which should update the following  4 fields:
[Impresion] [varchar] (50) COLLATE Modern_Spanish_CI_AS NULL ,
      [Etiquetas] [varchar] (50) COLLATE Modern_Spanish_CI_AS NULL ,
      [ContEtiq] [text] COLLATE Modern_Spanish_CI_AS NULL ,
      [EspecEst] [text] COLLATE Modern_Spanish_CI_AS NULL
...BUt I can't delete and add now that I have 2 actions. What I have to do is use a stored procedure to first see if the [CodigoCliente] exists, if it does, it should do an update for the appropriate fields; if not, it should add a new record to the table.  How can I do this?

thanks,

Joseph
ASKER CERTIFIED SOLUTION
Pratima Pharande

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 3 Answers and 12 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 3 Answers and 12 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros