Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 Help with a stored procedure

Author  Topic 

Darkmatter5
Starting Member

17 Posts

Posted - 2012-06-04 : 17:19:43
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?

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2012-06-04 : 17:32:27
Use + instead of & to concatenate strings in T-SQL.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2012-06-05 : 05:26:08
Why are you printing them? Just return values of both the variables to the client and let it displays the message

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -