I'm trying to email customers in a table when TableA.Location value is NULL. Basically:
if TableA.Location IS NULL
then send an email to the value specified in TableA.Email_ID
Everything works if I have a single result from the query i.e. if only one record meets the argument then an email is sent. However it is not working for multiple results. I get the following error:
Subquery returned more than 1 value. This is not permitted when the subquery follows =, !=, <, <= , >, >= or when the subquery is used as an expression.
I'm new to SQL but it seems I need a IF THEN ELSE NEXT query or similar. Can anyone help please?
declare @newline varchar(10)
declare @body varchar(1000)
declare @footer varchar(100)
declare @emailid varchar(100)
set @newline = CHAR(13) + CHAR(10) + CHAR(13) + CHAR(10)
set @footer = 'To change your details please use the following link:'
+ @newline +
'abc' + @newline +
'123' + @newline +
set @body = 'The following details need to be updated:' + @newline
SELECT @body = @body + (rv_custom_incorrect_org.surname + @newline)
WHERE rv_custom_incorrect_org.location_name IS NULL
set @body = @body + @newline + @footer
set @emailid =
WHERE rv_custom_incorrect_org.location_name IS NULL)
@recipients = @emailid,
@subject = 'Request to Update Your Customer Details',
@body = @body,
@body_format = 'TEXT'