Posts by Sorack • 27,430 points
864 posts
-
1
votes2
answers309
viewsA: How can I only enter a certain amount of records into sql server?
You can create a TRIGGER which will check the current amount of records in the table hoteis_fotos and if you identify that there are already 10 records, it will cause an error with the message that…
-
4
votes1
answer394
viewsA: Change the type of a column in several tables in SQL Server
You can make a CURSOR to go through the tables that have that column and run the ALTER TABLE to change the type: SET NOCOUNT ON; DECLARE @schema VARCHAR(50), @tabela VARCHAR(50), @coluna VARCHAR(50)…
-
1
votes2
answers46
viewsA: mysql query that groups the distances travelled each day
I simplified your table as follows only to facilitate resolution: Schema CREATE TABLE location( dateGenerated DATETIME, Conductor VARCHAR(100), odometer NUMERIC(15, 3) ); INSERT INTO…
-
0
votes1
answer86
viewsA: SQL return relationship data on the same line
As of 2017 version of SQL Server you can use the function STRING_AGG that allows grouping and concatenating results: SELECT pptm.product_id, STRING_AGG(pptm.producttag_id, ', ') AS producttag_id…
-
1
votes1
answer427
viewsA: Separate results from an SQL query by date
You can create a CTE with the days between the dates as follows: WITH dias AS ( SELECT CAST('2019-07-01' AS DATE) AS dia, 1 AS sequencia UNION ALL SELECT CAST(DATEADD(DAY, 1, dia) AS DATE),…
-
0
votes1
answer88
viewsA: Popular table using two that has no link
You can make a CROSS JOIN that is nothing more than a JOIN no links between the tables, which will "join" all the records in table 1 with all the records in table 2: INSERT INTO…
-
3
votes2
answers75
viewsA: Looking for a group of duplicate records
You can make a query which counts occurrences in the table where the reference is within the proposed values, using the clause COUNT. After that just use the clause HAVING to check if the number of…
-
1
votes1
answer42
viewsA: Perform file Reload without Restart
You can use the function fs.watchFile to verify changes in this file and then perform the necessary action: const path = request('path'); const fs = request('fs'); const CAMINHO =…
-
2
votes2
answers223
viewsA: Merge an Object with an ES6 Javascript Object Array!
You can use the reduce to map the properties: const converter = (origem, mapa) => { return mapa.reduce((acumulador, { text, value }) => { return { ...acumulador, [text]: origem[value], }; },…
-
1
votes2
answers83
views -
0
votes1
answer76
viewsA: How to capture class attribute with Cheerio?
Missing to inform attribute gzip in his request: Crawler.request({ gzip: true, method: 'GET', url:…
-
1
votes2
answers75
viewsA: List only if the other table does not have a dismissal
Use the NOT EXISTS as follows: SELECT f.CodFuncionario, f.funcionario_Nome FROM funcionario f WHERE f.funcionario_CodEmpresa = 179 AND EXISTS(SELECT 1 FROM examefuncionario ef WHERE…
-
2
votes2
answers191
views -
1
votes2
answers485
viewsA: Parent class array with two different subclasses
Your code has several problems and improvements that can be made, but in short, the answer to your question is: Why are you saying that c is an instance of Cliente and this class doesn’t have the…
-
1
votes12
answers208289
viewsA: How to format date in Javascript?
You can format using template string: const formatar = (data) => { const ano = data.getFullYear(); const mes = (`00${data.getMonth() + 1}`).slice(-2); const dia =…
-
2
votes1
answer299
viewsQ: How to run multiple instances of an image on different ports?
I have an image docker door 8080. To execute it I use the following command: docker run -d -p 8080:8080 -e DB_URL="127.0.0.1:BANCO" -e DB_USERNAME="usr" -e DB_PASSWORD="XXXXX"…
-
1
votes2
answers412
viewsA: How to use BETWEEN and LIKE together in a Query?
You need a BETWEEN: SELECT * FROM dbo.nome_da_tabela WHERE dt_inicial BETWEEN '$data_incio' AND '$data_final' BETWEEN Specifies a range to be tested. Syntax test_expression [ NOT ] BETWEEN…
-
0
votes1
answer54
viewsA: Search and add table data in form [Nodejs and Mongodb]
You can wait for the completion of the promises: router.get('/unidade/add', async (req, res) => { try { const [countries, cities, municipalities] = await Promise.all([Country.find(), City.find(),…
-
3
votes2
answers720
viewsA: SQL SERVER | Fill empty fields in select
Use a OUTER APPLY in the same table to select the last completed record before you want: SELECT a.linha, CASE ISNULL(a.num_lcto, '') WHEN '' THEN ref.num_lcto ELSE a.num_lcto END AS num_lcto FROM…
-
1
votes1
answer1859
viewsA: How to fix "EPROTO" error after updating Node version?
The error indicated is the unsupported protocol or protocolo não suportado. Probably the address certificate cidadao.sinesp.gov.br is signed with TLSv1.0 and from the version v11.4.0 of Node.js the…
-
0
votes1
answer178
viewsA: Error listing posts with Node.js and sequelize
You did not export the module inside the file Post. At the end of your file add the following line: module.exports = Post;
-
1
votes1
answer255
views -
0
votes1
answer52
viewsA: Date Subtraction and return positive SQL value
To know if the result will be positive the second date must be greater than the first: SELECT DATEDIFF(DAY, cr.PagamentoData, cr.Vencimento) FROM Contas_Receber cr WHERE cr.vencimento >…
-
0
votes1
answer1859
viewsQ: How to fix "EPROTO" error after updating Node version?
The following code works in the version v10.15.3: const { post } = require('request'); const { post } = require('request'); post({ url:…
-
0
votes1
answer1782
viewsA: Sum of SQL accumulated value
You can recover the desired result with the following query: DECLARE @inicio DATE; DECLARE @fim DATE; DECLARE @material INTEGER; SET @inicio = '2019-05-17'; SET @fim = '2019-05-20'; SET @material =…
sql-serveranswered Sorack 27,430 -
3
votes1
answer669
viewsA: Set variable with SELECT and WITH in SQL Server
WITH CTE_R AS ( SELECT e.ID_Pessoa, ROW_NUMBER() OVER(ORDER BY ID_Pessoa) AS RowNum FROM Empresa e WITH(NOLOCK) ) SELECT @id_empresa = ID_Pessoa FROM CTE_R WHERE RowNum = 1 But in reality you have…
-
0
votes1
answer207
viewsA: Case When with Leftjoin
You may not use the CASE to decide which JOIN will do. Instead do both queries separate and use a UNION: SELECT x.* FROM ( SELECT p.id AS idpedido, p.*, i.*, e.*, f.*, m.id AS idempresa,…
-
2
votes1
answer526
viewsA: Async/Await, where are you wrong?
If you are using async/await no need to use the then: const url = 'http://files.cod3r.com.br/curso-js/funcionarios.json'; const axios = require('axios'); const busca = async () => { const { data…
-
3
votes2
answers548
viewsA: How to use Mysql SELECT + WHERE + IN with Javascript array?
You will need to enter the values directly into your query: const parametros = part_numbers_array.map((item) => "'${item}'").join(','); this._connection.query(`SELECT * FROM tab_price_list as PL…
-
1
votes2
answers500
viewsA: Selecting data and organizing by 15min Sql interval
You can create a CTE with the possible intervals within the times you have determined and so cross the data you already have. For the ranges use the clause WITH as follows: DECLARE @inicio DATETIME…
-
1
votes1
answer1678
viewsA: Pass header value for Nodejs API
You can pass the parameters to the function get: const headers = { token: 'TEXTO DO TOKEN', }; const parametros = { url: 'APIURL', headers, }; request.get(parametros)...…
-
0
votes5
answers2691
viewsA: Array, how to apply in this question?
You can use the filter function: filter The method filter() creates a new array with all the elements that passed the test implemented by the provided function. This function executes another one…
-
0
votes1
answer229
viewsA: Nodejs send server files to server
You can use the module request, more specifically the sending of Forms as follows: const request = require('request'); const fs = require('fs'); const path = require('path'); const enviar = (campos,…
-
4
votes3
answers315
viewsA: Would it be possible to list Enum from a table field through a query?
You can use the table information information_schema.columns separating the information as suggested in the answer to the question Split column into multiple rows (split). Schema (Mysql v5.7) CREATE…
-
4
votes2
answers432
viewsA: Select from multiple tables with the same ID in Mysql
It seems to me the case of using the UNION: SELECT a.aw_token AS token, 'ax_det' AS tabela FROM ax_det a WHERE a.aw_token = '834545' UNION SELECT ar.ar_token AS token, 'ax_det1' AS tabela FROM…
-
3
votes4
answers620
viewsA: How to round off this number: 3084.08 SQL SERVER?
Use the function ROUND together with CAST of SQL Server: SELECT CAST(ROUND(3084.087522295, 2) AS NUMERIC(15, 2)) as X Resulting in 3084.09. ROUND Returns a rounded numerical value for the specified…
-
2
votes2
answers705
viewsA: SQL Error: Can’t reopen table
From the MySQL 8.0 you can use the clause WITH instead of the temporary table: WITH alteracoes_oportunidades AS ( -- SELECT que reunirá o conteúdo da, até então, tabela temporária ) SELECT a.* FROM…
-
1
votes1
answer373
viewsA: Remove partition from table
ALTER TABLE t1 REMOVE PARTITIONING; REMOVE PARTITIONING REMOVE PARTITIONING Enables you to remove a table’s partitioning without otherwise affecting the table or its data. In free translation:…
-
1
votes1
answer206
viewsA: error when connecting mysql with Node.js
To set the port with the function createConnection you must inform the door inside the property port: // ... const con = mysql.createConnection({ host: 'localhost', port: 806, user: 'root',…
-
1
votes1
answer372
viewsA: Number of consultations held Nodejs
Create a middleware to carry out the count: const contador = 0; const adicionar = async (req, res, next) => { contador += 1; next(); }; const contar = () => { return contador; };…
-
1
votes1
answer49
viewsA: Is importing module into the loop a bad practice?
You should import the module only once. The preference is that it be at the beginning of your file. If you use incremental values within your function, you can use a class to create a new instance…
-
1
votes1
answer452
viewsA: Use proxy in nodejs to access external files
You can use the module axios to perform the request in conjunction with the module https-proxy-agent to define the proxy. To use anywhere in the application, create a module within your application.…
-
1
votes1
answer34
viewsA: How to get the most distant date in Mysql?
Sort your results by the difference between the table date boi and the date of the table boi_manejo. Then limit the number of results to just one. Schema (Mysql v5.7) CREATE TABLE boi ( id INTEGER,…
-
2
votes2
answers1278
viewsA: String or Binary data error would be truncated - SQL
You are trying to add a higher value than the column allows. Your column CodigoAudinUJ has size 6 and you are trying to insert 13 characters.
sql-serveranswered Sorack 27,430 -
3
votes2
answers158
views -
0
votes1
answer329
viewsA: I cannot get result from my updated object list
The problem is that the request is asynchronous. Or you enter the res.send within the callback of db.query or rewrites using promise: const firebird = require('node-firebird'); const attach =…
-
2
votes1
answer131
viewsA: Global variable inside require Node.js
Its function album makes a request, which in turn is asynchronous, so you should work with promise or callback. To use promise you can perform the following change in function: function album(music)…
-
2
votes3
answers172
viewsA: Hide duplicate SQL values
Use the UNION: SELECT t1.campo1 FROM tabela1 t1 UNION SELECT t2.campo2 FROM tabela2 t2
-
0
votes2
answers367
viewsA: Sort an array in Javascript
Create a dictionary of letters in the order you want within a array; Create a array with the normal letters of the alphabet; Separate the words from the phrase you want with split by space; Index…
-
0
votes1
answer62
viewsA: Bring certain record first in SQL query
Make the adjustment on ORDER BY of query: ... ORDER BY CASE principal WHEN 'S' THEN 0 ELSE 1 END; The clause ORDER BY indicates how the data presentation will be sorted. In the above case we say…