Quantcast
Channel: Microsoft SQL Server
Viewing all articles
Browse latest Browse all 4871

SQL Stored procedure help needed

$
0
0

I have a stored procedure that adds a customer record and check for duplicates entries before adding the new record. The procedure check is on the name and surname fields.

My goal is to prevent the same user from entering duplicates entries.

I'm getting hung-up on syntax:

SQL
ALTERPROCEDURE[dbo].[insert_customers]@titlevarchar(4),@namevarchar(50),@surnamevarchar(50),@addressvarchar(50),@postcodevarchar(50),@cityvarchar(50)ASDECLARE@countintSELECT@count=0SELECT@count=COUNT(*)FROMcustomersWHEREdbo.customers.name=@nameANDdbo.customers.surname=@surnameIF(@count=0)BEGINSETNOCOUNTON;SELECTid,title,name,surname,address,postcode,cityFROMcustomersINSERTINTOcustomers(title,name,surname,address,postcode,city)VALUES(@title,@name,@surname,@address,@postcode,@city)PRINT'Customer record...

Viewing all articles
Browse latest Browse all 4871

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>