Here's my basic code:
USE [byrndb]
GO
IF OBJECT_ID('spDeleteCounty') IS NOT NULL DROP PROCEDURE spDeleteCounty
GO
CREATE PROC [dbo].[spDeleteCounty]
@ID int
AS
IF NOT EXISTS (SELECT * FROM surveys WHERE CountyID = @ID)
BEGIN
DELETE FROM counties WHERE CountyID = @ID
END
ELSE
BEGIN
DECLARE @CountyName varchar(50) = (SELECT counties.CountyName
FROM surveys
JOIN counties ON counties.CountyID = surveys.CountyID
WHERE surveys.CountyID = @ID)
DECLARE @Count int = (SELECT counties.CountyName
FROM surveys
JOIN counties ON counties.CountyID = surveys.CountyID
WHERE surveys.CountyID = @ID)
PRINT 'The selected county of "' & @CountyName & '" is associated with ' & @Count & ' survey(s). Disassociate the county with those surveys prior to attempting to delete it.'
END
I'm wanting to get two items and output them in a print. When I try and execute I get the following error.
"Msg 402, Level 16, State 1, Procedure spDeleteCounty, Line 20
The data types varchar and varchar are incompatible in the '&' operator."
Any thoughts?