Questions tagged as 'tsql'

2
answers

SQL Query - CASE with LEFT JOIN

I need to create a query that returns all active students and their grades for each subject. If the student does not have a grade for a given subject, the student must return the subject and note the value "No grade". I think I'll need to cre...
asked by 20.05.2017 / 23:38
1
answer

Odd Row Queries SQL SERVER

I need to create query script that returns from the table only its odd rows, sorted in ascending order: DECLARE @table TABLE (coluna1 varchar(50)) INSERT INTO @table VALUES ('Anthony'),('Miguel'),('Benjamin'),('Lucca'),('Enzo'),('Martim'), ('N...
asked by 23.11.2017 / 16:06
2
answers

CURSOR vs table-type variable

I'm facing one of those situations where I need to perform an action for each row resulting from a query. In this way I have two options, to use a Cursor or a Table Variable , however the two seem to me very similar (semantically...
asked by 26.03.2015 / 20:37
1
answer

Go line by row of a table

I have a temporary table that I fill in with the result of a given query. I need to move the data from this temporary table, line by line, and pick certain fields and insert them into another table, and in that other table, generate a coupon...
asked by 19.12.2016 / 20:40
1
answer

Replace in Date within a FOR

I want to return the last 12 months, the day should come as 01 and need month and year. ex: 2014-12-01 2014-11-01 NOTE: I placed yyyy-mm-dd only by a pattern of mine. I'm doing this: DECLARE @count INT DECLARE @Data_Atual DATE SET @cou...
asked by 08.01.2015 / 19:05
1
answer

Relationship 1: N check date, difference 6 month

I'm developing a SQL Server procedure, which lists two tables: WhereaprocesshasN-statements,Ineedtoreturnthefollowingdata:allProcessNumbersthatarewiththeIrrecuperavel(int)=1columnandthe"last" date entered in the Process table for that% Proce...
asked by 28.11.2017 / 17:10
1
answer

Spending only one year on a sql server 2014 proc

I made a filter in a proc and I can not bring results. When running the proc it did not give any errors, but it does not bring any result and I do not know if it is correct. The colleague said that I do not need to pass any parameters, I do not...
asked by 17.04.2017 / 14:26
1
answer

How to use LEAD and LAG using a condition

My question is, if I can use LAG and LEAD, using a condition in the query, for example: I have the zip column .. I want to get the value of the next line, and the value of the previous line in that same column. I'm working with C # and SQL...
asked by 29.04.2014 / 18:38
1
answer

Assign a variable to a Dynamic Data?

My goal is to create a procedure in SQL Server , which has by default two variables, one with the start date of (hoje - 3 anos) and another as the end date equal to hoje . I already use for other operations (for example a between)...
asked by 23.05.2017 / 20:22
1
answer

IF in StoredProcedure within a select, remove sp_executesql @query

I have a StoredProcedure that unfortunately only because of an IF it stopped being a select and turned everything into a VARCHAR statement and then I execute it, losing one of the main benefits of MSSQL being compiled. I modified SP just to...
asked by 16.01.2015 / 12:24