Sql Exec Problemas

Asked

Viewed 26 times

0

Well, I’m trying to execute the command below, but it’s always giving error, someone knows why?

declare @maquinaCount varchar(max);
declare @maquinaOnline varchar(max);

select @maquinaCount = 'select count(id) from Indigo_Nextel_Portabilidade_Dev6.bko.OnlineMachine';

select @maquinaOnline = 'select count(id) from Indigo_Nextel_Portabilidade_Dev6.bko.OnlineMachine where bol_online = 1';
exec(@maquinaOnline);
exec(@maquinaCount);
insert into TB_METRICA(Metrica_Nome, Metrica_MaquinaQuant, Metrica_MaquinaOnline) values('Nextel Portabilidade', exec(@maquinaCount), exec(@maquinaOnline));
  • What error? If you do not specify the error it is very difficult to suggest an answer

  • the variables are not carried out.

  • And there’s some special reason you use exec instead of just throwing the value at variables?

1 answer

0

By the structure of the code and by tags of the question, you are doing all this in sql even, in the database itself. So, you can do the query directly, without needing to store the command in variables and execute.
So I could set @maquinaCount and @maquinaOnline with the quantities:

declare @maquinaCount int;
declare @maquinaOnline int;

select @maquinaCount = count(id) from Indigo_Nextel_Portabilidade_Dev6.bko.OnlineMachine    
select @maquinaOnline = count(id) from Indigo_Nextel_Portabilidade_Dev6.bko.OnlineMachine where bol_online = 1

insert into TB_METRICA(Metrica_Nome, Metrica_MaquinaQuant, Metrica_MaquinaOnline)
values('Nextel Portabilidade', @maquinaCount, @maquinaOnline)

As for the error you are receiving, probably the fields MaquinaQuant and Metrica_MaquinaOnline are of numerical type, and those declared in their code are varchar(max)

Browser other questions tagged

You are not signed in. Login or sign up in order to post.