Most voted "sql-server" questions
SQL Server is a relational database management system from Microsoft. Use this tag for all SQL Server editions, including Compact, Express, Azure, Fasttrack and PDW.
Learn more…2,752 questions
Sort by count of
-
2
votes1
answer116
viewsIs Sqlserver’s HASHBYTES() function cryptographically secure?
The company I work today she has much of the programming done in the database through procedures and was seeing how the creation of the hash of passwords and their persistence in the bank. I…
-
2
votes1
answer1022
viewsRecover last inserted id and selected stroke
I have the following situation: On the same form, I insert a student: SqlCommand inserirAluno = new SqlCommand("INSERT INTO ALUNOS (Nome, DataNascimento, CPF, Endereco, Bairro, " + "CEP, Cidade,…
-
2
votes4
answers27603
viewsSQL - Calculate percentage in the same select
Based on the query below, I need to add the column Percentage, being the calculation of Passed on top of the Total but I do not know how to take the values of this same select to insert in the…
-
2
votes1
answer42
viewsHow can I timeout an attempt to connect to SQL Server using sqlalchemy?
I have a list of 200 hosts to connect. The problem is that when I try to connect to a host that is not available, it takes about 10 seconds for me to receive an exception telling me that I have not…
-
2
votes1
answer81
viewsCount in Past Time Intervals
Good morning ! I have a view with contracts, and in it there is a column for Dtiniciovigencia (DATE) and a column Dtfimvigencia (DATE). I needed to count the number of active contracts for each of…
-
2
votes1
answer82
viewsMerge Names into a line
Good afternoon we use SQL SERVER 2008 as the official database server and we have the following query : SELECT P.NOME AS [PROFESSOR], STIPOCURSO.NOME AS [NÍVEL DE ENSINO], SPL.CODPERLET AS [ANO],…
sql sql-server query sql-server-2008 string-concatenationasked 6 years, 6 months ago Nathann L. J. Lima Alcantara 21 -
2
votes2
answers271
viewsHow to eliminate duplicate lines without using distinct?
The query below returns me the following: IF object_id('tempdb..#tmpHistorico') IS NOT NULL BEGIN DROP TABLE #tmpHistorico END CREATE TABLE #tmpHistorico ( Id int not null, IdColuna1 int not null,…
-
2
votes1
answer25
viewsTest for the absence of duplicate tuples
I saw in a SQL book the following query: select T.course_id from course as T where unique (select R.course_id from section as R where T.course_id = R.course_id and R.year = 2009) I am unable to…
-
2
votes2
answers143
viewsConcatenate the field and group the rest
I have the following query: SELECT finempe.data_empenho , finempe.num_empenho , finhisem.quantidade , finhisem.historico , finhisem.valor , finhisem.valor_total FROM finempe RIGHT JOIN finhisem ON…
-
2
votes1
answer98
viewsError creating an executable distribution with sql database using Entity Framework
I am developing a C# winforms desktop application in Visual Studio with Sql database through the Entity Framework. The intention is that it be a local database, the program will be installed on…
-
2
votes1
answer48
viewsResult Hierarchy prioritization in a view (Largest Record and Order specifies within the largest record)
I am putting together a structure within a view where I am working with market levels (retail segment). Following this idea I have a product that can contain more than one current registration; it…
sql-serverasked 4 years ago Bruno Araujo Santana 21 -
2
votes1
answer501
viewsEntityframework + Sql Server + ASP.NET MVC
Hello, I have an ASP.NET MVC application that is using the ORM Entityframework to communicate with an SQL Server database! I currently switched computers and had to install everything again, Visual…
-
2
votes1
answer477
viewsError trying to add time field(varchar) sql server
I have a query that returns the following data: SELECT * FROM METAS mes lj saldo meta 4 2 153:59 123:00:00 4 2 25:33 00:00:00 4 2 29:57 08:00 4 2 38:58 45:00:00 4 2 94:47 20:00 4 2 23:41 15:00:00 4…
-
2
votes1
answer541
viewsStorage of List-like variables in an SQL-Server database
Good Evening Everyone, I am developing an application that makes a relationship between a Player and one or more games(online games), the problem is that a game can have one more different skills, I…
-
2
votes2
answers428
viewsCursor problem: SQL Server
I have a problem with the cursor part: cursor with the name 'Cursobanco' does not exist. Sql code: if @Opcao='1' begin set @tipoPagamento='20' set @LayOut='040' declare CursoBanco Cursor LOCAL…
-
2
votes2
answers85
viewsAdd rows with the same ID in additional columns
I have the following Table scenario: +-------------------------------------------------------------+ | ID | DATA | PROFISSAO | SEQUENCIA | +-------|…
-
2
votes1
answer153
viewsCount/Dense_rank sql grouped
I’m trying to group the lines by group on sqlserver and as a result I want to: CICLO | CODFIL | CODITPROD | ROW 1 | 1 | 10 | 1 11 | 1 | 10 | 2 12 | 1 | 10 | 3 1 | 2 | 10 | 1 11 | 2 | 10 | 2 1 | 3 |…
-
2
votes3
answers1447
viewsHelp select to bring field even if null
I need help to create a select, I have 4 tables (commission, person, request, pedidoitem). So I need to bring in all the people and their goal values even if they don’t have values yet. I made a…
-
2
votes1
answer77
viewsCalculate the time difference without giving the date
I’m trying to figure out the difference between two hours. However, I would not like to give the dates. I would like to know for example that between 23:00 and 01:00 it was 120 minutes. What I tried…
-
2
votes3
answers658
viewsCompare 2 field-to-field tables
I have two tables with equal fields. Table A and B I need to compare the contents of the two tables field by field. I am using the following code to find records that have some different field, but…
-
2
votes1
answer456
viewsExtract xml tag from a varchar(max) column
Hello, I have a series of xml records in a varchar(max) column and need to extract the tag <MT_USADA>16 MB</MT_USADA>, for example: <?xml version="1.0" encoding="utf-8"?>…
-
2
votes1
answer321
viewsField condition with subquery
Example of select: SELECT campo1, (ROUND(((t3.quantidade * t2.distancia * (SELECT TOP 1 valor FROM frete WHERE datainicio <= t1.dataemissao AND tipo = t4.tipo ORDER BY DATAINICIO DESC)) -…
-
2
votes4
answers1185
viewsChange only the day of registration
Scenario (example): I have the following table: ID | TIPO | DATAINCLUSAO 1 | 10 | 21/07/2018 09:34:51 2 | 10 | 11/07/2018 11:15:25 3 | 11 | 23/07/2018 01:52:31 4 | 11 | 04/07/2018 23:24:52 5 | 12 |…
-
2
votes2
answers62
viewsChange the end of the email domain to a random scan
Hello! I’m looking for a way to mask emails in the database, but in a way that I can reverse them without much difficulty, in case I need the real email. My idea is to create a Rigger AFTER INSERT…
-
2
votes2
answers60
viewsColumn type List
I worked a long time with Postgresql and now with SQL Server I have missed some features that made life much easier. I have for example a table that one of your columns should be a list of strings,…
sql-serverasked 6 years, 2 months ago Matheus Saraiva 2,157 -
2
votes2
answers1445
viewsUPSERT or UPDATE-INSERT?
Across of that question felt the need to research and understand a little about the UPSERT. I was wondering What blessed command is that? I’ve never seen.. I found some information but it is not…
-
2
votes1
answer3485
viewsChange varchar field yyyy-mm-dd hh:mm:ss to data dd/mm/yyyy in SQL Server
Guys, I’m extracting the data from a satisfaction survey log, and I’m trying to create a column with the date format, so I can group the days and months into an Excel dynamic table. For more…
-
2
votes1
answer528
viewsError: SQL Server String or Binary data would be truncated
I have the variable @numero1 which brings the following result: 020000000000720000018 But at the time of update gives error: SQL Server String or Binary data would be truncated declare @g1…
-
2
votes2
answers377
viewsTimout when searching between 2 date intervals
I have a query where I make a query between 2 date ranges. On those dates, I apply the DbFunctions.TruncateTime to filter searches only by dates, ignoring the time. Obs: are fields Datetime .Where(p…
-
2
votes0
answers59
viewsDead Lock with SQL SERVER PROCEDURE
I need to generate a table of games for four groups with 5 teams, for each day a total of games must be held, at the time that the PROCEDURE which executes the insertion starts is called the…
-
2
votes1
answer97
viewsAdd another sum result
I’m trying to make a sum of the result of another operation. Below is the code I’m trying to select distinct (SELECT(SUM(CAST(ROUND(ppre.Valor_Custo, 2) as decimal(18,2))) )) * (select…
-
2
votes1
answer630
viewsNodejs query in SQL Server
Hello, guys I need to make a query filtered for days in SQL in a Nodejs application, but during the POST that’s when I filter the Nodejs accuses me of a value conversion error. When running get I…
-
2
votes1
answer873
viewsError executing report in SQL Server Reporting Services
The following error is occurring while running a Reporting Services report: "Report processing error. (rsProcessingAborted) Not possible to create a connection to the data source 'Production'.…
-
2
votes1
answer201
viewsShow NULL SQL values
Good evening, I’m new to SQL and I have a question. I have the following database: My goal is to present the name of the employees, their function and the name of the department where they work…
-
2
votes1
answer160
viewsError when using ISDATE in CASE WHEN
Hello, everybody. I am running the query below and is showing the error: "Operand type Clash: int is incompatible with date". My intention in performing this query is to validate whether the field…
-
2
votes0
answers266
viewsHow to avoid Database Lock using Entityframework Transaction
I have a method where I save several classes and call another method to do an optimization on top of these classes, but I am using Transaction, in case something goes wrong in this optimization I…
-
2
votes1
answer1210
viewsSelect with subquery to catch previous record
I have a user readout log structure by reference. As shown below. SELECT L.LeituraID, L.UsuarioID, L.Referencia, L.Leitura FROM Leituras AS L |-----------|-----------|------------|---------| |…
sql database sql-server query performanceasked 5 years, 11 months ago Danilo Ribeiro da Silveira 143 -
2
votes3
answers3588
viewsHow to store more than one value in an "SQL variable"?
I work with a system that has a very limited report. The reports are basically restricted to one sql query. I need to present in a report a query that, in my query, is being informed by the user a…
-
2
votes1
answer45
viewsHow to sum the first 2 occurrences of a column using a key as 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:…
-
2
votes1
answer78
viewsConcatenation of Records via FOR XML PATH - SQL SERVER
Good afternoon dear, I have the following problem: I am developing a Query where I need to verify which documents were delivered by the student, documents that are in the table pre_matricula_doc and…
-
2
votes1
answer56
viewsHow to return table values using the SUM() function?
I have the following tables CREATE TABLE tbCliente ( ClienteID INT IDENTITY(1,1) PRIMARY KEY, ClienteNome VARCHAR(50), ClienteTelefone VARCHAR(15), ClienteDataCadastro DATE) CREATE TABLE tbPagamento…
-
2
votes0
answers189
viewsGeneric Repository with Dapper
I’m doing a test application where I want to see performance and learn about creating a generic repository with Dapper, well I have some experience when creating a generic repository, but using EF6,…
-
2
votes1
answer116
viewsHow to convert 39 hours to 'TIME' type
To accomplish a certain task, I count in my system the time spent of the respective task. Today I came across the following: Data Inicial: 17/12/2018 16:49:14 Data Final: 19/12/2018 08:02:58…
-
2
votes1
answer361
viewsError trying to import . Bak file from Sql Server on Linux
I am very beginner in SQL Server and am trying to import a file . Bak from a backup that came from another server (Windows) on Linux (Linux Mint 19) The command I used in the terminal was that:…
-
2
votes1
answer86
viewsQuery to update field from one table based on another
Good morning, I need to update the values of one table based on the values that are in another. I need the first table to update only the data contained in the second, for example, in the first…
-
2
votes4
answers2042
viewsSelect with 3 tables in SQL SERVER
I need to make a select in the machine table, but when I run my command select maq.maqNip, equi.* from tblMaquina maq join tblEquipamento equi on equi.equId = maq.maqTipoEqui; the following result…
-
2
votes1
answer1343
viewsHow to change 2 or more columns at the same time in Sql Server 2014? (ALTER TABLE/ALTER COLUMN)
How do I change 3 columns at the same time in the SQL SERVER table? I want to change the COLLATION, but it could be something else. I tried to: ALTER TABLE dbo.SIX_POSTO ALTER COLUMN VIS_DS…
-
2
votes2
answers4510
viewsRound Up SQL SERVER
I’m making a SUM(x) and I need to divide it by 8, for this example, my result will be 5.5. The result needs to be like an INT and rounded up.. So for this example, I need the result 6. I’ve already…
sql-serverasked 5 years, 9 months ago LeoHenrique 954 -
2
votes1
answer241
viewsHow to select by comparing two columns
Considering the following structure: Coluna_A | Coluna_B | 01 João | Carro | 02 João | Moto | 03 Maria | Moto | 04 José | Carro | 05 Maria | Moto | I’d like to perform a select to bring me the…
sql-serverasked 5 years, 9 months ago Fabio Souza 1,859 -
2
votes1
answer71
viewsSELECT of Header and Items of an XML
Hello, How can I select one XML with header and items? I have it: DECLARE @XML XML = CONVERT(XML,' <ROOT v="2.15.0"> <LOTEANIH APP="00B1" LOTE="1"> <LOTEANIM ANIMAL="10" />…