Questions tagged as 'sql-server'

2
answers

How to use the WHERE clause over a column made from row_number () over ()

I am trying to use the where on top of a column generated by row_number but it does not work; is it possible to do this?     
asked by 23.09.2018 / 00:48
4
answers

Select from previous months

I need to select in data from previous months, month by month. My query looks like this: SELECT * FROM VIEW_INCD WHERE MONTH(DH_CRIA_INCD) = DATEPART(mm,GETDATE()) - 1 AND YEAR(DH_CRIA_INCD) = YEAR(GETDATE()); Okay, I select only t...
asked by 08.08.2018 / 15:19
1
answer

How not to bring a certain column in SQL, using IF and ELSE?

Gentlemen, I have a table where I want to bring the column when the value is null but when it is filled it should not be displayed, how can I implement this condition in SQL? SELECT OBS.NUOBS, OBS.DTOBS, OBS.CODUSU, OBS.OBS,...
asked by 19.09.2018 / 15:46
2
answers

How to return a special character in a query

Good morning! It may be simple to doubt, but I'm starting in SQL Server yet, so I'd like to know how to return a select a special character. As you can see, there is the presence of a single quote in the Nat_Rec field and I can not put it in...
asked by 11.09.2018 / 13:46
1
answer

Merge columns into a single SQL column

I have three columns, belonging to the same table in the database, these being: Growth, Financial Autonomy and RaciLiquidity; All columns are of type bit. What I need is to group all three fields into one column, that is, if I do: SELECT Is...
asked by 13.03.2018 / 11:37
3
answers

SQL Query - Doubt Condition Dates

Everyone, good afternoon! I'm having trouble with the query below. I want you to bring all the tasks only when the maturity (field) of them is equal to the month after the opening date (tardata). However, nothing came up in the query. select *...
asked by 01.12.2017 / 19:04
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

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