Questions tagged as 'sql'

2
answers

How to check Null in a select @Local_Variavel

How to set a default value for a local variable, if the select that should "set" it returns NULL ? For example: DECLARE @Minha_Var VARCHAR(70) SELECT @Minha_Var = Nome FROM CLIENTES WHERE Id = 10 This query can return NULL , ri...
asked by 25.10.2017 / 12:06
1
answer

Select grouping by average per hour and sum per day

How can I return a select the daily sum of the value column, being that before adding I have to do an average per hour? My table receives the "value" once per second, I need to average the hourly value of that value and return the sum of these a...
asked by 26.10.2017 / 23:56
1
answer

SQL distinct with sum

Hello, I have a problem making a sum in a query. Query example and results: select DISTINCT t.ID, t.nomeuc as "Nome UC", t.tipoturno as "Tipo Turno", a.num_presencas as "Número de Presenças" from ei_sad_proj_gisem.v_aulas_semana a jo...
asked by 03.11.2017 / 22:06
2
answers

Delete and reallocate index

How do I associate data to have a SQL Server 2017 db with good performance. I am making a data association and being new in this area I feel a bit lost. I have the following structure as an example: Let'ssaythattheabovestructureshavethef...
asked by 19.11.2017 / 20:27
1
answer

Conversion from VARCHAR to INT

I'm trying to do INNER JOIN but the fields are in VARCHAR. In a field I have cod_authorization = 749831164 And in the other field I have num_aut = 000749831164 Because of zeroes to " Left " the connection does not work. I thought...
asked by 12.07.2017 / 17:06
1
answer

Difficulty building an SQL statement

I have broken my mind here to build a SQL, maybe someone can help me. I'm trying to write a report to collect the relationship of notes that were eventually deleted. The user registers an nf in the system that has the initial status "relat...
asked by 01.09.2017 / 04:00
3
answers

Validate whether the INSERT was executed successfully or not (JTDS)

I would like to know a form of validation to know if the insert was executed successfully, I have no idea how to do this because the execute () method does not return anything! Connection connInsert = DriverManager.getConnection(ConnectionURL)...
asked by 28.08.2017 / 21:58
2
answers

Change the last part of the e-mail domain to a random varchar

Hello I'm looking for a way to mask emails in the database, but in a way that I can revert to them without much difficulty if I need the actual email. My idea is to create a AFTER INSERT trigger for this. Will not be used in production en...
asked by 15.08.2018 / 20:51
1
answer

Problem in a simple Update with Inner Join

I'm running a simple update on my base, however the set I'm giving is being replicated to all rows in the table. Follow the script you ran: update reference_vendor set internalid = v.internal_id from reference_vendor rv inner join c...
asked by 06.08.2018 / 22:21
2
answers

Check birthdays of the current month in SQL [closed]

I need to run a birthday visit for the current month. But I would like it to be automatic, and not have to enter the month. Below is the example I made by typing the month. NOTE: My field is dt_nasc (TIMESTAMP) . SELECT * from top_007 wher...
asked by 27.09.2017 / 19:58