Hamza Shah

Hamza Shah

  • NA
  • 87
  • 21.3k

If (City Id) does not exist in “CustomersInfo” table then create a new

Feb 25 2021 10:05 AM
I'm working on a project where I've made a Store procedure to load Bulk of customers data in CustomersInfo table. There is customer's City Id in a table. So i want when there is new city of customer then new city will added to City table. I'm not getting the logic to do that. can anyone please help me.
 
Here's my Store Procedure
  1. alter procedure sp_AddCustomerBulk  
  2. @CompanyId int,  
  3. @jsonstring nvarchar(max)  
  4. as begin  
  5. select * from OPENJSON(@jsonstring)  
  6. WITH (MemberId int,CompanyId int,ShopId int, MemberName nvarchar(500), CityName nvarchar(50), CityAreaName nvarchar(50), Email nvarchar(50), PhoneResident nvarchar(25), PhoneOffice nvarchar(25), PhoneMobile nvarchar(25), Comments nvarchar(500) , MemberDOB datetime , MemberAnniversary datetime , CNIC nvarchar(20) , Gender nvarchar(10), CreditLimit numeric(18,4) , AllowCredit bit , MemberAddress nvarchar(500) , MemberTypeName nvarchar(50) , OpeningBalance money)  
  7. end

Answers (2)