0
Good morning, I’m having difficulty to do in sql server 2014.
I need the result back exec (@query)
create a dynamic table with this result filling in with columns and rows.
Query I’m using to mount:
DECLARE @COLS VARCHAR(MAX)
,@QUERY VARCHAR(MAX)
SET @COLS = STUFF((
SELECT ',' + QUOTENAME(A.MOTIVO)
FROM #TMP_GERAR A
group by A.MOTIVO
-- ORDER BY A.MOTIVO ASC
FOR XML PATH('')),1,1, '');
SELECT @COLS
SET @QUERY = 'SELECT * FROM
(
SELECT REPRESENTANTE,
HORARIO,
motivo
FROM #TMP_GERAR
) AS EX
PIVOT
(
MAX(HORARIO)
FOR motivo IN ('+@COLS+')
)AS X'
-- aqui que gostaria de ter um uma tabela criada
--dinamicamente para receber o resultado desta variavel
EXECUTE ( @QUERY)
Goal is to create an HTML email with the table created, this is the only way I know so far.
Thanks in advance
Do you say create the email and send by SQL Server itself? I don’t understand what’s dynamic in this story
– Leandro Angelo
Hello, this is a comment for my goal after being able to create the dynamic table, if it is the case do not need to read this goal which is just an observation.
– Jameson
Where do you want to read this table?
– Leandro Angelo
read in a table in the email would that be it? not understood just wanted to do type this example nor works select into ##table from @query, I just can’t get the names of columns pq do not know which or how many have seen.
– Jameson