Posts by rLinhares • 7,797 points
331 posts
-
4
votes2
answers1719
viewsA: How to search two words in the same Mysql field
You must use the clause IN: SELECT * FROM Produtos WHERE Tags IN ('Audiômetro', 'Impedanciômetro', 'OEA', 'BERA', 'Vectonistagmógrafo'); edited whereas the countryside Tags contains more than one…
-
1
votes2
answers775
viewsA: How to sort an Array alphabetically in PHP?
You can use usort() function cmp($a, $b) { return strcmp($a["nome_ultimo_campo"], $b["nome_ultimo_campo"]); } usort($tabela, "cmp"); In that question was raised something like what you need.…
-
1
votes1
answer33
viewsA: How to get higher repetition index value in a php string
Use the function array_count_values(): $array = array(4,1,2,1,1,1,3,1,2,5,3); $total = array_count_values($array); Thus, $total will be a array as below: $total ( [1] => 5 [2] => 2 [3] => 2…
-
3
votes3
answers1524
viewsA: If with 3 conditions and at least 2 true?
I don’t know if there’s a way "automatic" to control it, but you can group the conditions: if ((a && b) || (a && c) || (b && c))…
-
0
votes2
answers576
viewsA: Extract Date from a C#String
Try the code below: string teste = "Aprovados por autorizantes da aplicação -> 02/03/2018 à > 02/03/2019"; string[] testeSplit = teste.Split('>'); string dataIni, dataFim; dataIni =…
-
4
votes2
answers456
viewsA: Count words in Array
I’ve needed something like this before; this is not the easiest way to understand but it was the most "beautiful" I have already used (found in this answer of OS): var totais = {};…
-
1
votes1
answer72
viewsA: Error storing byte in mysql db
Try using the Encoding.GetBytes() byte[] bytes = Encoding.ASCII.GetBytes(DBAcess_0.Tables[0].Rows[i]["RequiredLevel"].ToString()); In that reply you can see an example of using the Encoding,…
-
0
votes2
answers103
viewsA: Doubt with Joins in HQL query
You need to define how tables connect. As it stands, all the lines of t1 join those of the t2, t3 and t4. select distinct count(t.id) from tabela1 t left join t.tabela2 t2 on t2.fk_t1 = t1.pk_t1…
-
3
votes2
answers106
viewsQ: Performance of ternary operator
I recently came across an assignment to a boolean variable as follows: bool varTeste = (varEntrada == 100) ? true : false; I know this is the same as the code below: bool varTeste = (varEntrada ==…
-
2
votes1
answer101
viewsA: How to display data in java Arraylist
In class Aluno you can overwrite the toString(): @Override public String toString() { return ("Nome:"+this.getNome() + " Telefone: "+ this.getTelefone()); } And use this structure on main: public…
-
2
votes1
answer43
viewsA: Select only the days of a Timestamp
You can use DATE_PART(), where the structure would be DATE_PART('day', dataFim - dataIni). SELECT (select count(numeroserie) as porcentagemTotal from public.lotesretornosuprimento where laudo =…
postgresqlanswered rLinhares 7,797 -
0
votes1
answer218
viewsA: DATE_FORMAT - Mysql function
You can specify the fields you want to bring from the table: select id, DATE_FORMAT( `resolution` , '%d/%c/%Y' ) AS `resolution`/*, demais_campos*/ FROM denuncia WHERE resolution BETWEEN…
-
1
votes1
answer289
views -
1
votes2
answers83
viewsA: Query mysql return 4 Counts same table
The structure of CASE is a little different in the mysql; try the code below: SELECT sum (CASE status WHEN 'pgto_confirmado' THEN 1 WHEN 'pending' THEN 1 ELSE 0 END) as new sum (CASE status WHEN…
-
1
votes1
answer126
viewsA: Group by error of a query in db2 SQL
Error says you need to add all clauses that are not sum() at the group by. Try it this way: Select ITEMNFS.Recnum, ITEMNFS.ITEM, sum(ITEMNFS.VL_TOTAL), sum(ITEMNFS.QTDE_FATUR), ITEM.PER_IPI from…
-
2
votes1
answer43
viewsA: Date query in mysql?
The scolding is that the function WEEK() returns a number between 0 and 53; according to the year, the day may not be in the same week (e.g.: in a year the day 06/01 is in the week one, in the other…
-
2
votes3
answers582
viewsA: How to remove spaces before and after a string without the Javascript "Trim()" method
By your idea would need to stop the going when finding the "first nonseparator" and start a new one backwards, following the same idea. I got carried away doing it here.. see if this meets :P…
-
4
votes3
answers964
viewsA: Use of 'break' in Javascript
I don’t think there’s a "break everything", but you can play this loop in a function and finish it, it would circumvent the problem: function ExibirNum(){ var i, j; for (i = 1; i <= 3; i++) { for…
javascriptanswered rLinhares 7,797 -
3
votes3
answers100
viewsA: Convert decimal to ushort
There is a specific function for conversion into ushort which is the Convert.Touint16(). Try it like this: static void Main(string[] args) { decimal value= 15; //Nao é possivel converter, pergunta…
-
6
votes1
answer27466
viewsA: How to convert string to int type in c
If your idea is to convert string to int, you should use atoi: char num[10] = "100"; int valor = atoi(num); detail: in C there are specific functions according to the type of input and output:…
-
3
votes3
answers1235
viewsA: Replace value null
As stated in the other answer, use the ISNULL, but in this way: SELECT ISNULL( (SELECT TOP 1 tabela1.data FROM tabela1 tabela1 WHERE tabela1.id = tabela2.id), '1900') as data FROM tabela2 tabela2…
-
0
votes2
answers812
viewsA: Get previous element in foreach
As Gabriel commented on, "by definition the foreach will invoke the Ienumerable.Getenumerator to make its increment, it does not use the index as the for". But there is an alternative (which I…
-
1
votes2
answers62
viewsA: Search Object Array value
I believe that this iteration will bring the expected result: var valorFinal = 0; for (i = 0; i < Filmes.length; i++) { for (j = 0; j < Cliente.length; j++) { if (Cliente[j] ==…
-
1
votes2
answers404
viewsA: Get data from all days of the months in the query range
A way for you to get to that starting day that you need would be this: cast(cast(year(DATEADD(year, -1, GETDATE())) as varchar) + '-' + cast(month(GETDATE()) as varchar) + '-01' as smalldatetime) So…
sql-serveranswered rLinhares 7,797 -
1
votes2
answers66
viewsA: Query between tables
untested code I couldn’t test it here, but here’s the idea: create a temporary table to store what matches each jovem and monitor who live in the same city; in the query, add the total of…
-
4
votes2
answers78
viewsA: A single SQL query for a user’s products!
Just remove the id_produto of where, so you will bring all user products consulted: SELECT id_produto, produto, (SUM(credito) - SUM(debito)) as producao_total FROM produtos_farm PF INNER JOIN…
-
0
votes3
answers95
viewsA: how could I use instead of passing an id, passing a Class in JQUERY?
You can use this butter: $('.submit1, .submit2').click(function () { if ($(this).attr('class').indexOf('submit1') >= 0) { alert('Submit 1 clicked'); } else if…
-
1
votes1
answer271
viewsA: Group Month according to Between
Basically you need to add the year to the grouping (for cases where your query brings an interval greater than a year, so the values will be specific to each month/year) and to the ordering (so that…
-
2
votes3
answers2936
viewsA: Check last record of an sql table
The above answer is correct, when you define the id (or any field in the table), the query will only bring whatever has that specified value. There are some alternatives to the proposed solution…
-
-1
votes1
answer62
viewsA: Remove 'R$' before converting to Double
Tries that answer: var linha = $(this).parent('td').parent('tr'); var valor = Number(linha.find('td:eq(1)').text().replace(/[^0-9\.-]+/g,""));…
-
0
votes1
answer137
viewsA: Combine SQL queries with different columns
updated response I believe the idea is to turn the two into one, since you need data of the two. Try this query below: SELECT finempe.codigo_orgao ,finempe.cod_reduzido ,finempe.num_empenho…
sql-serveranswered rLinhares 7,797 -
2
votes1
answer953
viewsA: Random Numbers without repetition.(Javascript)
To not change the structure of your code too much, basically you will change the line jogo.push(Math.round(Math.random()*20)); to use this structure: while(i<=6){ var novoNum = -1; do { novoNum =…
-
0
votes1
answer36
viewsA: Hide a table after clicking
I think that that answer is just what you need: $('#tabelaCliente td a').click(function() { //o que precisar fazer.. $('#tabelaCliente').toggle('slow'); });…
-
0
votes1
answer38
viewsA: Sqlquery - Some Duplicate Records
I believe that this duplication is in the second query, where you use the Union all. One-night stand in that reply but briefly, the Union all considers duplicate items for consultation. I believe…
-
0
votes2
answers2257
viewsA: ORA-00907: Missing right parenthesis error
Considering that your second query is correct, I believe the mistake is that you did not put the AND between the first and the second condition of where. Try it this way: (SELECT SUM( SCORE + GRADE…
-
1
votes2
answers56
viewsA: Query SQL Server - Union
The point is that the Union brings really different lines, so you just need to group these results in a single: SELECT Consultor, UsuID, SUM([Tentativa 1 Abertos]) FROM ( select U.UsuNome Consultor,…
-
0
votes2
answers53
viewsA: Doubt about Querys
The error is that in internal queries you do not consider the item id, so it always returns the total. I believe this should solve the problem: SELECT B.ID_Caso, B.Nome_Caso_Teste AS PRODUTO,…
-
3
votes2
answers1027
viewsA: How to count the number of lines in a file. csv
The problem is you’re in loop infinite; you only check if you are at the end of the file but don’t iterate. Try like this: while (!feof($f)) { $linhas += 1; $f->next(); }…
-
0
votes1
answer48
viewsA: How I take the value of a checkbox to go through parameter
If the idea is to check if the check in is marked, the query should be done as below: var checkado = $("#chkAguardandoEnvio").prop("checked"); If it is known whether the check in is enabled for…
-
3
votes2
answers67
viewsA: Convert Data Sqlserver
According to that answer of the SO, the code you want is the 103: select CONVERT (datetime, '02/01/2018', 103)…
-
3
votes3
answers2090
viewsA: How to add Count output from different tables in SQL Server?
If you’re not so concerned about performance, you can use the query below: select sum(total) from (SELECT count(*) as total from OBRAS union all SELECT count(*) as total from TITULOS union all…
-
0
votes2
answers71
viewsA: This code is leading me to an infinite cycle and I can’t figure out why
If I understand the code correctly the problem is in the method ordena; how do you have a for covering all the positions of the r, doesn’t need the while(1). The loop was because the t == 0 never…
-
3
votes5
answers2297
views -
3
votes2
answers999
viewsA: Which is more efficient, perform multiple queries or use JOIN?
I think the best solution would be to group everything into a single query: SELECT Y.*, Z.* FROM X JOIN Y on Y.id = X.id JOIN Z on Z.attr1 = Y.attr1 WHERE X.id = @id You could remove the table X of…
-
4
votes2
answers80
viewsA: How to create a condition that does not include the month of December?
The query you need to make is this, using the Month() to know only the month of the date SELECT * FROM Tarefa WHERE TarID = @Tarefa and month(TarFechamento) <> 12…
-
0
votes3
answers171
viewsA: Doubt - Update SQL Server 2012
The charindex should solve your problem: declare @MesAno varchar(50) select @MesAno = CONCAT(DATENAME(MONTH,getdate()),'-',DATEPART(YEAR,getdate())) select @MesAnoAnterior =…
-
1
votes3
answers1724
viewsA: Add Datagrid column with valid values only
If the point is just not to add those that do not contain value, try this code: public void Somatorio() { decimal total = 0; foreach (DataGridViewRow row in dgv_inico.Rows) { if…
-
1
votes2
answers215
viewsA: Selection with various differences conditions (SQLSERVER)
You can use the NOT IN: SELECT * FROM table WHERE id not in (15, 17, 23/*, N*/)…
-
2
votes3
answers608
views -
1
votes1
answer87
viewsA: Picking last value of each ID according to highest end year
whereas the ano_inicial is stored as whole: select f.id_user as user, f.id_tempo, t.ano_inicial, t.ano_final from fato as f inner join tempo as t where f.id_tempo = t.id_tempo and t.ano_inicial =…