Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Sending emails to several users from a query
Message
 
 
À
27/04/2009 22:36:36
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Autre
Divers
Thread ID:
01396601
Message ID:
01396898
Vues:
97
I would recommend to read BOL and follow the syntax provided in it. Try
DECLARE @Rrecipients varchar(max), @Subject varchar(max), 
		@Body varchar(max), @Query varchar(max)

-- Get the list of recipients
SELECT @Rrecipients = ISNULL(@Rrecipients + ';', '') +  Usuario.Email + ';' + Usuario_1.Email
	FROM ResponsablePropuesta 
		INNER JOIN Propuesta ON ResponsablePropuesta.Idpropuesta = Propuesta.IdPropuesta 
		INNER JOIN Prospecto ON Propuesta.IdProspecto = Prospecto.IdProspecto 
		INNER JOIN Estado ON Propuesta.IdEstado = Estado.IdEstado 
		INNER JOIN Usuario ON ResponsablePropuesta.RespGrupo = Usuario.IdUsuario 
		INNER JOIN Usuario Usuario_1 ON ResponsablePropuesta.RespPropuesta = Usuario_1.IdUsuario
	WHERE(DATEDIFF(y, GETDATE(), ResponsablePropuesta.FechaPlanEntrega) = 1)

SET @Subject = 'Mensaje de prueba'
SET @Body = 'Don Jose, si le llega este correo por favor confirme a.' 
-- Query to run for the body of email
SET @Query = 'SELECT * FROM DbName.dbo.tableName ... '

EXEC msdb.dbo.sp_send_dbmail 
	@recipients = @Rrecipients,
	@subject = @Subject,
	@body = @Body,
	@query = @Query
>I can send emails now from SQL, but I was wondering how to send emails to several recipients from a query and also the body contain information from another query. I used:
>
>USE sipcopia
>GO
>EXEC msdb.dbo.sp_send_dbmail @profile_name='CorreoHelpdesk',
>@recipients='SELECT     Usuario.Email AS responsablegrupo, Usuario_1.Email AS responsablepropuesta
>FROM         ResponsablePropuesta INNER JOIN
>                      Propuesta ON ResponsablePropuesta.Idpropuesta = Propuesta.IdPropuesta INNER JOIN
>                      Prospecto ON Propuesta.IdProspecto = Prospecto.IdProspecto INNER JOIN
>                      Estado ON Propuesta.IdEstado = Estado.IdEstado INNER JOIN
>                      Usuario ON ResponsablePropuesta.RespGrupo = Usuario.IdUsuario INNER JOIN
>                      Usuario AS Usuario_1 ON ResponsablePropuesta.RespPropuesta = Usuario_1.IdUsuario
>WHERE     (DATEDIFF(y, GETDATE(), ResponsablePropuesta.FechaPlanEntrega) = 1)',
>@subject='mensaje de prueba',
>@body='Don Jose, si le llega este correo por favor confirme a.' 
>
>but it seems not working. How can i solve this?
--sb--
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform