if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[sp_Insert_T_FR_PATIENT]') and xtype = N'P')
DROP PROCEDURE  [dbo].[sp_Insert_T_FR_PATIENT]
GO

--SET ANSI_NULLS ON
--GO
--SET QUOTED_IDENTIFIER ON
--GO
--Create procedure [dbo].[sp_Insert_T_FR_PATIENT] (
--@Snils as varchar(255)
--, @FirstName as varchar(255)
--, @LastName as varchar(255)
--, @FatherName as varchar(255)
--, @Birthday as datetime
--, @Sex as int
--)
--as

--if not exists (select 0 from [AKUZ].T_SNILS where Snils = @Snils)
--insert [AKUZ].T_SNILS (Snils) values (@Snils)

--if exists (select 0 from [AKUZ].T_FR_PATIENT where Snils = @Snils)
--update [AKUZ].T_FR_PATIENT set
--FirstName = @FirstName
--, LastName = @LastName
--, FatherName = @FatherName
--, Birthday = @Birthday
--, Sex = @Sex
--where Snils = @Snils
--else
--insert [AKUZ].T_FR_PATIENT (FrPatientID, Snils, FirstName, LastName, FatherName, Birthday, Sex)
--values (NEWID(), @Snils, @FirstName, @LastName, @FatherName, @Birthday, @Sex)