get query result with trigger
Hello, I want to get the code in the line when insert, I will use the code I received in a query and create a table, Then I will send this table to the interested parties by e-mail,
I created a trigger, I got the code in insert, My sorghum is ready, My mail sending code is ready,
Problem: I can't create table with sql query
create trigger DilmeEmriMailGonder
on [db].[dbo].[Table1]
After insert as
Begin
DECLARE @DilmeEmri nvarchar(max);
DECLARE @tableHTML nvarchar(max);
DECLARE @Konu nvarchar(max);
select @DilmeEmri= s_code, @Konu=s_code+' - Dilme Emri Oluşturuldu' from inserted
set @tableHTML=
N'<table border="1" cellspacing="0" cellpadding="0" width=95% style="border:solid #DFD7CA 1.0pt;" >'+
N'<tr style="height:22.7pt"><th>Dilme Emri</th><th>İş Emri</th><th>İşin Adı</th><th>Kağıt Kategori</th><th>Kağıt Alt Kategori</th><th>Kağıt Kodu</th><th>Kağıt Adı</th><th>Ölçü</th><th>Miktar</th><th>Makine</th>'+
CAST((
SELECT
td =ctt.[s_code],'',
td =tq.s_orderID,'',
...
FROM [db].[dbo].[Table1] ctt
left join [db].[dbo].[Table2] cttd on ...
left join [db].[dbo].[Table3] tp on ...
left join [db].[dbo].[Table4] te on ...
....
where ctt.s_code=@DilmeEmri and ctt.b_deleted=0
for xml path('tr'), type )as nvarchar (max)) +
N'</table>'
exec msdb.dbo.sp_send_dbmail
@recipients = 'mail@mail.com',
@subject = @Konu,
@body=@tableHTML,
@body_format='HTML'
End