Questions tagged as 'tsql'

3
answers

SQL Server - Query logic

Look at the result below: This is the result of the following query: select *, isnull(h,isnull(f,isnull(d,isnull(b,isnull(a,0))))) as y1, isnull(h,isnull(g,isnull(f,isnull(e,isnull(d,isnull(c,isnull(c,0))))))) as y2 from valor My...
asked by 01.07.2018 / 01:25
3
answers

I have this cursor and the 'between' where it gives error. I would like to select the years from 2005 to 2008

DECLARE @Year int DECLARE db_cursor CURSOR FOR Select distinct Year(OrderDate) as Year From Sales.SalesOrderHeader Order by Year(OrderDate) OPEN db_cursor FETCH NEXT FROM db_cursor INTO @Year WHILE @@FETCH_STATUS = 0 BEGIN --INSERT INTO xxxx...
asked by 11.08.2017 / 18:47
1
answer

Filter query by removing duplicates

Good afternoon, I have the following select : select codemp, codfunc, codevento , vlrevento from sankhya.TFPFOL where codemp = 1 and codfunc = 26 and month(referencia) = 1 and year(referencia) = 2009 group by codemp, codfunc, codevent...
asked by 21.12.2018 / 17:34
2
answers

How to Automatically Name a CONSTRAINT Manually Created in SQLServer 2016

Hello, I'm creating a database and I need to create some compound indexes to optimize the bank's processing. The problem is that I do not want to have to name those indexes one-by-one. Normally, I create a table as follows: CREATE TABLE Usua...
asked by 22.08.2018 / 17:53
1
answer

Subquery returned more than 1 value. This is not permitted when the subquery follows =,! =, = =

I have a procedure that sends email with the table data, including the email that will be forwarded, but it is sending to only the 1 record, the second it goes straight, and it's in Infinite Loop, sending multiple Emails to just the 1st r...
asked by 28.10.2015 / 14:35
1
answer

How to check if a view exists before having it created?

Take the following view as an example: CREATE VIEW vw_types AS SELECT codigo AS code, nome AS description, abreviacao AS abbreviation, statusRegistro AS status FROM tipos How can I have it created only if it does not ex...
asked by 24.02.2015 / 14:14
0
answers

How to sum the first 2 occurrences of a column using a key as a reference in SQLServer

Hello, I have the following table: create table events ( type int not null, value int not null, time datetime unique(type, time) ); Where in the same I have the following records: ------------------------------------------...
asked by 29.11.2018 / 20:13
5
answers

MySQL Limit Equivalent in SQL Server

Does anyone know how to relate the differences between MySQL and SQL Server, including using LIMIT n,n ? Or if they have a link that lists the differences would be cool. Example SELECT * FROM tabela LIMIT 50, 100 What would be the...
asked by 26.03.2014 / 17:01
0
answers

Special characters breaking XML in SQL SERVER

I recently had a problem reading an XML, where the value of the field seems to have a special character. Below is the snippet I created for the problem declare @xml as xml set @xml = '<ConsumerList> <Consumer> <Sourc...
asked by 10.07.2018 / 20:52
0
answers

Replacing characters in SQl Server tables

I need to replace some strings in a database. I AM TRYING WITH: UPDATE dbo.ModeloMensagem SET corpoMensagem = REPLACE(dbo.ModeloMensagem.corpoMensagem, '<', '[') WHERE dbo.ModeloMensagem.corpoMensagem IN (SELECT DISTINCT(dbo.CampoTipoMen...
asked by 11.04.2018 / 15:19