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
-
0
votes1
answer203
viewsCount separate records with filtering condition in another field
Staff need to perform a count of how many distinct records exist in a field, but my filtering condition is based on another field. Example of how the data are organized: PDV | DESC ----------------…
-
0
votes1
answer46
viewsnull check on substring
I need to have a check in case I don’t have a comparison with some null value, I’m not able to make it work this condition. AND SUBSTRING(CAST(CONVERT(NVARCHAR(10),LE.DTHREMPRESTIMO,103) AS…
sql-serverasked 4 years, 9 months ago PedroBelino 176 -
0
votes1
answer105
viewsDatabase based query listing
First of all, I apologise if the question is vague, as it is a very broad subject. Today I have a student registration and consultation system, where the query is made exclusively by CPF, since it…
-
0
votes1
answer95
viewsReturn data from 01 column in 03
I am working with some data in a table, in which I made a SELECT that one of the columns returns the status of the processes that are in progress in our queue. The data in this column are for…
-
0
votes1
answer472
viewsSELECT TOP that brings all the results, something like TOP all, exists in SQL Server?
During my studies, I tried to sort the records and put those that are NULL in the end, I did it this way: SELECT tbl1.firstname, tbl1.mgrid FROM ( SELECT TOP 100 firstname, mgrid FROM HR.Employees…
-
0
votes1
answer104
viewsHow to select only the first row of row_number
SELECT SA.RA, PP.NOME, SC.COMPLEMENTO, SPL.ANO, ROW_NUMBER() OVER(PARTITION BY SA.RA ORDER BY SPL.ANO ASC) AS U_PERLET I am doing this select, is returning all data with a count, the count is done…
sql-serverasked 4 years, 8 months ago PedroBelino 176 -
0
votes1
answer75
viewsCreating database in Visual Studio
If I create the database of my project in Visual Studio it will always use the T-SQL language to create the manipulate? Or I can create the entire database with the relationships and everything in…
-
0
votes2
answers550
viewsSQL Server - Select last 7 days from the last record
Guys I’m beginner in SQL and it’s complicated to solve this problem that came up.. I need a select in SQL-Server that returns: the sales of the last seven days. For example if the last day there was…
-
0
votes1
answer636
viewsProblem with accentuation when exporting data from Sql Server to Excel
I have the following code inside a button responsible for performing the export of data from my table to excel. string caminho = "c:\\caminho"; // criar um arquivo para escrever using (StreamWriter…
-
0
votes1
answer359
viewsRecover sequential auto increment after deleting some column
I am using SQL server and the scenario is that I have a table with an auto increment id field, for example I have 3 field inserted, in case there are the ids 1, 2 and 3, if I delete the column with…
-
0
votes2
answers132
viewsHow to change EF6 to create Datetime fields as datetime2
I am working with **EF6 Code-first", SQL-Server database. I came across the following error, when saving an object with Datetime property. The Conversion of a datetime2 data type to a datetime data…
-
0
votes0
answers12
viewsHow to Get information from a column of a column of a table and a column of another table and display in one result?
/In this case I want to take all orders made in 1997 and the value of the 10 best and show however the years is in the Orders table and the value is in the Orders Details table/ select Orderdate…
sql-serverasked 4 years, 6 months ago Breno Carneiro 1 -
0
votes0
answers152
viewsCharacter replacement in Sql Server tables
I need to replace some strings in a database. I’M TRYING WITH: UPDATE dbo.ModeloMensagem SET corpoMensagem = REPLACE(dbo.ModeloMensagem.corpoMensagem, '<', '[') WHERE…
-
0
votes3
answers6516
viewsHow to convert varchar to Numeric in SQL?
I am trying to make an SQL query, but it returns the following error: "Error Converting data type varchar to Numeric." SELECT Tabela1.CPF, Tabela2.CPF FROM Tabela1 INNER JOIN Tabela2 ON Tabela1.CPF…
-
0
votes1
answer43
viewsIs giving this error qdo try to add data in table - 00928. 00000 - "Missing SELECT keyword
Is giving this error qdo try to add data in table - 00928. 00000 - "Missing SELECT keyword INSERT INTO DEPT ( DEPTNO, DNAME, LOC) VALUES (10, 'ACCOUNTING', 'NEW YORK'); (20, 'RESEARCH', 'DALLAS');…
-
0
votes2
answers156
viewsBirthday Ordering - SQL Server
Good night! I have an SQL Server Database with fields: Name and Birth Date. I must sort by the Birth Date, being the order of the nearest date to the most distant date, the intention in this order…
-
0
votes2
answers1317
viewsTurn rows into SQL columns
I have the following Query: SELECT distinct finmovem.num_transacao ,finempe.codigo_orgao ,finempe.cod_reduzido ,finempe.num_empenho ,finempe.data_empenho ,finempe.nome_fornecedor…
-
0
votes1
answer73
viewsHow do I pass a list of parameters to a precedent?
I want to pass N parameters of N types to a dynamic process. How can I do it? Example: struct = (Here the structure will be mounted with several parameters) struct.id = 123 struct.name='Marisa'…
-
0
votes1
answer42
viewsHow to insert multiple email addresses within one variable, in SQL?
For example: If instead of just typing an email address in the variable below, I typed 30 email addresses, which I would have to change in my query below? DECLARE @email as NVARCHAR SET @email =…
-
0
votes1
answer47
viewsBest Script Performance
I made a condition that way: If @dt_contabilizacao = @dt_operacional And Not Exists (Select 1 From tabela Where dt_mes_referencia = @mes_referencia) But the check of dt is not necessary since if…
-
0
votes1
answer824
viewsHow to create a CONSTRAINT CHECK in Sqlserver to validate versions with Regex
Hello I am creating a table in Sqlserver where I want to validate a field to only accept the correct version mask, like this: CREATE TABLE Versao ( id INT NOT NULL IDENTITY(1,1), codigo…
-
0
votes1
answer65
viewsBest way to ensure consultation isolation
I have the following scenario: A table in SQL Server that contains process records that can be run on multiple services (Windows Services in C#) from multiple servers. Something like: CREATE TABLE…
-
0
votes1
answer395
viewsConsider NULL as 0
In the following query I need the transaction value to be considered as 0 when it is NULL in the highlighted aggregation, how can it be done? I tried using isnull but it didn’t work SELECT…
-
0
votes0
answers630
viewsINNER JOIN with a SELECT TOP
When generating a script, I tried to modify a Where for Inner Join. However, the time when running with Inner Join was more than 10 minutes and with Where, it was in a matter of seconds, as the…
-
0
votes1
answer282
viewsI want to total the multiplication of two columns
SELECT ID_PRODUTO AS CODIGO, BARRAS AS CODIGO_BARRAS, PRODUTO AS NOME, ESTOQUE AS QUANTIDADE, CUSTO, **(ESTOQUE*CUSTO) AS VALOR_TOTAL -- A TOTALIZAÇÃO É PARA ESSA…
-
0
votes1
answer172
viewsRecursive query does not return records when the parent product and the child product have the same code
I have a table that maps a production line. The fields are: Product: Machine Output Product. Parentproduct: Input Product. Machine: Code of the machine. I’m using CTE s to get the data recursively.…
-
0
votes1
answer27
viewsSelect a date field by extracting only the month and year
I need to mount a Query that selects the sum of the vacant amount of each month in a period of one year. In case there would be several dates within each month that would have vacancies, which…
-
0
votes1
answer300
viewsSQL - Insert random values into a table
Hello I am trying to insert random values in the columns but without success. I tried that but I got nothing. Someone who can help please. Declare @NovosID int SELECT @NovosID=NovosID FROM…
-
0
votes0
answers25
viewsError while restoring Windows Forms Application Database
I am creating the database backup but cannot restore. It shows the following error: this is my code to perform bank restore to my application. try { var _with1 = openFileDialog1; _with1.Filter =…
-
0
votes0
answers26
viewsUpdate multiple databases with Entityframework
I have an application developed with React + API with . NET Core where I use Entityframework to run database migrations. The applications and databases (one for each customer) are all in Azure. I’m…
-
0
votes1
answer39
viewsRefresh a column every 2 hours
I have a column with values more accurate that every 2 hours it increases +1. for the player to buy as soon as possible. CREATE TABLE [dbo].[Produtos_Offer]( [x_Item] [int] NOT NULL, [Preço] [int]…
sql-serverasked 4 years, 2 months ago Jor 11 -
0
votes1
answer32
viewsSelect Same Field
Hello! I need to make an SQL that gives me the result and I wish in the same line. Today SQL is skipping a line. I need you to stay on the same line. select c.empresa, p.nome, (select…
-
0
votes1
answer114
viewsMessage appears when selecting value in a dropdownlist
I created a dropdownlist in Asp.net linked to a database. Now I want a message to appear as soon as one of the values of db is selected. (Ex: A dropdownlist with three values "A", "B", "C". When I…
-
0
votes1
answer264
viewsSELECT operation in PHP with SQL Server 2008
Starting in PHP with SQL Server 2008. I wonder what’s wrong with my code. <?php $serverName = "DESKTOP-B8EB4SG\SQLEXPRESS"; $connectionInfo = array( "Database"=>"contas", "UID"=>"sa",…
-
0
votes1
answer21
viewsShow item description only when equal to only appear as " null " or " No Description "
In Sqlserver, I need to appear in the Description column only values that have all the same values grouped in group by, otherwise show as null or Sem Descrição, when you have a different description…
sql-serverasked 4 years ago BrunoK 1 -
0
votes1
answer31
viewsQuotation Factor
The SQL below returns me quotation value, I need to find the quotation day factor that boils down like this: SQL SELECT SIMBOLO, CONVERT (VARCHAR(10),DATA,103) as DATA, FATOR FROM GCOTACAO WHERE…
-
0
votes1
answer27
viewsCompares sqlsrv_query with text
I am starting in PHP together with SQL Server 2008. The code below makes a query in the database and displays what was obtained. <?php $serverName = "DESKTOP-B8EB4SG\SQLEXPRESS"; $connectionInfo…
-
0
votes2
answers55
viewsGive an input in a table with information from two tables
I would like to know how to insert in a table ids of two other tables. For example, there are 5 tables one is student, which has the following information: +--------+------------+ | ID_ALU | nome |…
-
0
votes0
answers110
viewsQuery with duplicate result
Hello, I’m banging my head here, I don’t know where I’m going wrong, I’m still learning so any help will be welcome. Tabela Muser | MUser_USER_NUMBER | MUser_USER_NAME |…
sql-serverasked 4 years ago Kristian Francischini 11 -
0
votes1
answer30
viewsConcatenate lines into one
Good afternoon, I need to unify some data, when I bring this so: id 2017 2017-LOJA 2018 2018-LOJA 1 n n s s 1 s s n n Would like so: id 2017 2017-LOJA 2018 2018-LOJA 1 s s s s consultation I made:…
-
0
votes0
answers19
viewsError trying to create Sql Server database in Visual Studio (C#)
I’m trying to create a database in Visual Studio, but returns error as the capture screens even with active services. From now on, thank you.…
-
0
votes0
answers31
viewsError creating tables - ASPNET-CORE-C#
Good afternoon to you all. I am studying C# with Asp Net Core and I am having problems in a matter of a job. I need to create several tables (consultation, doctor, patient...) within the…
-
0
votes1
answer114
viewsinsert the license into SQL Server 2019 Standard Edition (64-bit) on Linux (Ubuntu 18.04.5 LTS)
Good morning Gentlemen(as) I installed SQL Server 2019 Standard Edition (64-bit) on Linux (Ubuntu 18.04.5 LTS) and after I bought the license, however I can’t find a tutorial or something that helps…
-
0
votes1
answer138
viewsSQL - Searching XML data
I have a table in which one of the fields is an XML The XML structure is the Brazilian standard schema of CTE (Electronic Transport Knowledge) <cteProc xmlns="http://www.portalfiscal.inf.br/cte"…
-
0
votes0
answers47
viewsEncrypt within the Database
Hello! I’m making a process for entering user data and would like to know how to encrypt the password field within the process. My table: create procedure cadUsuario( @nome varchar(100), @email…
-
0
votes1
answer18
viewsFind out what type of Encoding was used
Is there a way to find out what kind of encoding was used for a table field? I need to maintain a system, but I wanted to know if you have how to use sql server.
sql-serverasked 3 years, 11 months ago Clayton Prebelli 23 -
0
votes1
answer32
viewsSQL error in casting int to string
I have a method where I need to return the ID (integer) of a particular record whose name I pass as parameter, but Visual Studio points out the following error : Undefined object reference for an…
-
0
votes1
answer26
viewsCalling other data from an entity
I created a database entity and a dropdownlist. When I click on a list item, I want to call the other data. How do I ?? Follows code public ActionResult dbExample() { copaDBEntities entity = new…
-
0
votes3
answers255
viewsSQL bring result with repeated column numbers all only the largest
Hello guys I’m trying to get a data but I’m not able to filter the way I need, example : select a.cod, a.nome, b.pedido, b.versao from cliente a inner join pedido b On a.cod= b.cod order by b.pedido…
-
0
votes1
answer38
viewshow to consult database informed by variable?
Just an example of query sql server: SELECT A.name FROM [banco1].sys.procedures as A What I need is for this query above to be changed to something like: SELECT A.name FROM…
sql-serverasked 3 years, 11 months ago Fabio Santos 11