Hello All I would like to see an example how to check if pappssn exsist in database before the update is complete. If so to raise an error record exsist. My front end is VB however i would like to handle this within SQL in my stored procedure if possible. Any Ideas?
ALTER Procedure [dbo].[usp_insertmemapp](
@pappfname nvarchar(50),
@pappmname nvarchar(50),
@papplname nvarchar(50),
@pappwedding nvarchar(50),
@pappstateresidence nvarchar(50),
@pappstreet nvarchar(50),
@pappcity nvarchar(50),
@pappstate char(2),
@pappzip char(6),
@papphomephone nvarchar (13),
@pappfax nvarchar (13),
@pappaltstreet nvarchar(13),
@pappaltcity nvarchar(25),
@pappaltstate char(2),
@pappaltzip char(6),
@pappalthomephone nvarchar (13),
@pappaltfax nvarchar(13),
@pappssn char(11),
@pappdob nvarchar(50),
@pappcell nvarchar(13),
@pappemail nvarchar(50),
BEGIN TRY
BEGIN TRANSACTION
INSERT INTO [a_abacus].[dbo].[primaryapplicant]
VALUES(
@pappfname,@pappmname,@papplname,@pappwedding,@pappstateresidence,@pappstreet,@pappcity,@pappstate,
@pappzip,@papphomephone,@pappfax,@pappaltstreet,@pappaltcity,@pappaltstate,
@pappaltzip,@pappalthomephone,@pappaltfax,@pappssn,@pappdob,@pappcell,@pappemail,
Commit Transaction
END TRY
BEGIN CATCH
ROLLBACK
END CATCH
ALTER Procedure [dbo].[usp_insertmemapp](
@pappfname nvarchar(50),
@pappmname nvarchar(50),
@papplname nvarchar(50),
@pappwedding nvarchar(50),
@pappstateresidence nvarchar(50),
@pappstreet nvarchar(50),
@pappcity nvarchar(50),
@pappstate char(2),
@pappzip char(6),
@papphomephone nvarchar (13),
@pappfax nvarchar (13),
@pappaltstreet nvarchar(13),
@pappaltcity nvarchar(25),
@pappaltstate char(2),
@pappaltzip char(6),
@pappalthomephone nvarchar (13),
@pappaltfax nvarchar(13),
@pappssn char(11),
@pappdob nvarchar(50),
@pappcell nvarchar(13),
@pappemail nvarchar(50),
BEGIN TRY
BEGIN TRANSACTION
-- this is the important change...
IF NOT EXISTS (SELECT pappssn FROM a_abacus WHERE pappssn = @pappssn)
INSERT INTO [a_abacus].[dbo].[primaryapplicant]
VALUES(
@pappfname,@pappmname,@papplname,@pappwedding,@pappstateresidence,@pappstreet,@pappcity,@pappstate,
@pappzip,@papphomephone,@pappfax,@pappaltstreet,@pappaltcity,@pappaltstate,
@pappaltzip,@pappalthomephone,@pappaltfax,@pappssn,@pappdob,@pappcell,@pappemail,
Commit Transaction
END TRY
BEGIN CATCH
ROLLBACK
END CATCH