2
When I try to execute the following query, these two errors appear to me:
- Msg 207, Level 16, State 1, Procedure V_RECLAMACOES, Line 3 [Batch Start Line 0]Invalid column name 'Reason'.
- Msg 4413, Level 16, State 1, Line 43 Could not use view or Function 'dbo.V_RECLAMACOES' because of Binding errors.
This is my code, and I’ve also indicated where the bugs are:
use SAM_GestaoReclamacoes
declare @DESTINATARIOS nVARCHAR(max) = NULL, -- 1º erro
@tipo varchar(55) = NULL,
@diaBase date = NULL,
@ATUALIZAR_DADOS BIT = 0
declare @d date = dateadd(d, -4, getdate())
set @DESTINATARIOS = '[email protected]'
set @tipo = 'Mensal'
set @diaBase = @d
IF @DESTINATARIOS IS NULL
BEGIN
SET @DESTINATARIOS = '[email protected]'
END
IF @tipo IS NULL
BEGIN
SET @tipo = 'Mensal'
END
IF @diaBase IS NULL
BEGIN
SET @diaBase = GETDATE()
END
IF @ATUALIZAR_DADOS IS NULL
BEGIN
SET @ATUALIZAR_DADOS = 0
END
SET LANGUAGE Portuguese
IF @ATUALIZAR_DADOS = 1
BEGIN
DROP TABLE SAM_GestaoReclamacoes
SELECT *
INTO SAM_GestaoReclamacoes
FROM dbo.V_RECLAMACOES -- 2º erro
END
declare @top10reclamacoes varchar(max)
declare @html varchar(max)
declare @numero_reclamacoes_abertas_mes integer
declare @numero_reclamacoes_fechadas_mes integer
declare @startofcurrentmonth datetime
declare @dataini datetime
SELECT @numero_reclamacoes_abertas_mes = count(*)
FROM Reclamacoes R
WHERE R.Data >= DATEADD(month, -1, @startOfCurrentMonth)
set @html = '<html>
<body>
<font face="verdana" size="6"><b><u><center>INFORMAÇÃO PARA TODA A EMPRESA</center></u></b></font><br>
<br>
<font face ="verdana "size="5"><b><center>Número reclamações abertas este mês:' + convert(varchar(50), @numero_reclamacoes_abertas_mes)
SELECT @numero_reclamacoes_fechadas_mes = count(*)
FROM Reclamacoes R
WHERE R.DataConclusao >= DATEADD(month, -1, @startOfCurrentMonth)
And Tratado = 1
set @html = @html + '<br><br>Número reclamações fechadas este mês:' + convert(varchar(50), @numero_reclamacoes_fechadas_mes)
Select top 10 @html = @html + '<tr><td>' + convert(nvarchar(50), ID) + '</td><td>' + convert(char(10), R.Data) + '</td><td>' + ISNULL(convert(char(10),DataConclusao) , '') + '</td><td>' + convert(nvarchar(max), Exposicao) + '</td><td>' + convert(nvarchar(50), Tratado) + '</td></tr>'
From Reclamacoes R
Order by R.Data ASC
set @html = @html + '</html></table>'
print @html
Someone can help me?
I think something’s wrong with itself VIEW. Has effectively validated the column
Motivo
exists in the VIEWV_RECLAMACOES
?– João Martins
I can’t access the view, but I can access the column called complaints too, and there is no column called Reason but Idmotivo.
– Miguel Meireles
Then the VIEW is that it should be at the heart of the problem. If you don’t have access to it you won’t be able to solve it.
– João Martins
So thank you for your help @Joãomartins . I will try to talk to someone higher to see if I select this problem. Vlw
– Miguel Meireles
@Joãomartins, I also imagined that it might be a permission problem, maybe this solves the second error of line 43. I just don’t know what could have caused the error in row 3.
– RXSD
@Andréfilipe Because, this error of line 43 I was able to understand, now the error of line 3 I’m not really understanding what it might be.
– Miguel Meireles
You are probably using some column that does not exist, or that your writing is incorrect...
– RXSD
@Andréfilipe already managed to solve the two problems, the problems were in the table view.
– Miguel Meireles
What were the problems in the view?
– RXSD
somehow the motif column was not well "connected", the Inner Join in the two queries had not been well made.
– Miguel Meireles