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
-
1
votes1
answer83
viewsHow to list items per month in SQL Server
I need to be listed assets that have something scheduled for a period, in case they need to bring me by month, I’ll leave an example below: I have here a report where I bring an asset that returns…
-
1
votes2
answers266
viewsHow to increment a variable under a certain condition
I’m having a little problem with SQL. I need to increment a variable sel2 from a condition defined in sel1, for example: linha | sel1 | sel2 1 | 1 | 1 2 | -1 | -1 3 | -1 | -2 4 | 1 | 1 5 | 1 | 2 6 |…
sql-serverasked 5 years, 7 months ago Renato 11 -
1
votes1
answer57
viewsPrint days of the month in the table
I am trying to create a report based on some tables of my bank, in this report, I need to pass during the month, on which day the operation was executed, so I need to print out every day of the…
-
1
votes2
answers46
viewsHow to search for information in two different tables and return the ID of the table where the information is?
I have a code that could be of a natural person OR legal, and I have a table for each one (one for PF and another for PJ). I would like to find this user in one of the two tables and return your…
-
1
votes1
answer8888
viewsConcatenate columns in SQL SERVER
I need to concatenate 3 columns in a row using SQL Server, when I concatenate it returns this value: Would have to stay: Moura 105ah ground floor I’ve seen some examples on the internet, but I…
-
1
votes1
answer103
viewsHow to pull data from a login
I need to pull the value of the 'level' that is in the bank because I am setting in some pages the question of access permission , only that I am not able to pull this data from the table . Can…
-
1
votes1
answer445
viewsACCESS LEVELS - PHP + SQL SERVER
I have a table in my DB with the following columns : User , Password , Level and I need to make each level related to the person be redirected to different pages . How can I accomplish that ? Follow…
-
1
votes2
answers574
viewsCalculate Geometric Mean in SQL Query
Table Example Campo - Valor A - 30,21 B - 15,03 C - 5,06 B - 10,20 B - 12,89 C - 1,12 Geometric average calculation A = (30,21)^1/1 B = (15,03*10,20*12,89)^1/3 C = (5,06*1,12)^1/2 Results A = 30,21…
-
1
votes1
answer1163
viewsProblem with (Sql Server) insufficient system memory in Resource pool
I have a problem in some queries performed by the system, I analyzed the code and there is no error, more the bank is returning me to the message "There is insufficient system memory in Resource…
-
1
votes1
answer1116
viewsMake a "distinct" in a query with many fields in select
In this query, can I do a sort of distinct? A Group By is very slow and there are many fields. Pure distinct does not solve, as there are several fields. How would that be? DECLARE @CodTerceiro int…
-
1
votes1
answer599
viewsAs popular several select
I managed to make the second select (player) automatically load according to the first selected (tournament). I need to make the third (game) load according to the second. In my case, I have a team,…
-
1
votes1
answer33
viewsNumeric to Numeric Conversion Error
I have a stored file in the database that changes a record of a customer, entering the date on which it will be visited and the interviewer who will make the visit. CREATE PROCEDURE…
-
1
votes1
answer65
viewsHow to unite results of queries without mixing them?
How can I join 2 query results without mixing them? For example: The first query results in names starting with Victor, the second results in names containing Victor. Result of first consultation:…
-
1
votes1
answer43
viewsHandling of empty fields
In this query, I have some stores that have not identified sale. Bringing the result as null. This impacts on the field of percentage and total. How could I make null fields to be interpreted as 0…
-
1
votes2
answers500
viewsSelecting data and organizing by 15min Sql interval
Good afternoon, I have the following query that returns the amount of vehicles on the track between a certain time. But I want to take this interval between times and set intervals between 15min.…
-
1
votes1
answer669
viewsSet variable with SELECT and WITH in SQL Server
I am trying to set the variable with a query, select only works this way using WITH, but it is giving error when I will assign the value in the variable. The code I’m trying to: DECLARE @contador…
-
1
votes1
answer40
viewsDoubt - SQL Server - Using Union
Guys, I got the following Union: select cgc, item, matricula, cota, dataInicio, dataFim from [dbo].[cotas] as t1 where dataFim is null union select cgc, item, matricula, cota, dataInicio, dataFim…
-
1
votes2
answers45
viewsPlan properties in a single table
Consider the following classes: public class Pessoa { public int Id { get; set; } public string Nome { get; set; } public Telefone Telefone { get; set; } } public class Telefone { public string…
-
1
votes1
answer29
viewsHow to store records in tables when they have Foreign Keys?
My database has 6 tables: --Movies table MovieID int PK, MovieName varchar(50) MovieDescription text, MovieCategory varchar(50), MovieYear varchar(4), ParticipationID) --Series table SeriesData (…
-
1
votes1
answer69
viewsIs it possible to optimize my code for a single query?
I have the following problem: I’m assembling a Highcharts chart with queries php and I end up having a while inside another because the result of the date I put in the next query, has to return in a…
-
1
votes2
answers905
viewsProblem creating a Foreign key
I created a table tbl_cond with a PRIMARY KEY calling for ID_cond When creating a second table with a FOREIGN KEY, being her ID_cond of tbl_cond, put the following code. use db_clientes create table…
-
1
votes1
answer44
viewsC# Conversion Error when trying to save to SQL Server database
I’m new to C# and I’m taking a beating to record texbox data in SQL Server private void Btn_salvar_Click(object sender, EventArgs e) { using (SqlConnection con = new SqlConnection(strConexao)) {…
-
1
votes1
answer193
viewsHow to read position information that Cursor is in SQL Server
In the Cursor examples I found, to read the information I have to use the command: FETCH NEXT FROM In my code it’s like this: FETCH NEXT FROM CURSOR1 INTO @NAME - at the line Cursor is on I assign…
-
1
votes1
answer281
viewsQuery in an empty table
What is the return of a query in an empty table? Example, I am running this SQL Command: select Value from AVL_AnalogInput1 where TimeStamp = (select max(TimeStamp) from AVL_AnalogInput1) . Table…
sql-serverasked 5 years, 3 months ago Levi 665 -
1
votes0
answers40
viewsGet a company record
I am new in c#, I would like help to pick up and registered company by user X, what I need is the function Businessman Functioncontroller public async Task<IActionResult> Create() {…
-
1
votes1
answer206
viewsChanging Database of a system that is using EF code first
Please, I need to change the BD of an application using Mysql to use MS SQL Server. I have already migrated tables, data and relationships. The problem is that the system was made, I believe, in the…
-
1
votes1
answer69
viewsNODE.JS MSSQL use SQL NEWID() function as a variable value
Good afternoon! It has an SQL function (NEWID()) that generates a single key with this format: '6F9619FF-8B86-D011-B42D-00C04FC964FF' However, when I try to populate a column with the NEWID() value…
-
1
votes1
answer34
viewsSQL Insert when Inserted but Skip Duplicate
USE [RF_World] GO SET ANSI_NULLS ON SET QUOTED_IDENTIFIER ON GO CREATE TRIGGER dbo.UserStatusUpdater ON dbo.tbl_base AFTER INSERT AS BEGIN -- SET NOCOUNT ON added to prevent extra result sets from…
-
1
votes1
answer40
viewsDatabase occupied
public List<R> GetA(DateTime dataMov) { connection(); List<R> menuList = new List<R>(); try { con.Open(); using (SqlCommand cmd = new SqlCommand("SELECT r.nome,r.cos,r.estoque,…
-
1
votes1
answer43
viewsId booked in key breach transaction
I have the following question: In an operation of INSERT in a table when a key violation occurs and a ROOLBACK of the transaction, the ID still reserved? Below illustrative examples: Script of the…
-
1
votes1
answer1726
viewsHow to check if a Date field is NULL C# ASP.Net
I have a webservice where I make a query in a table of my bank where I have a column of type Datetime and I am wanting to make a check if this field Datetime is filled or if you are NULL I’m doing…
-
1
votes2
answers1604
viewsConversion of a data type scan into a data type datetime resulted in a value outside the yyyy-mm-dd range
I have a column called produtodata which has the following datetime format: 1753-01-01 00:00:00.000 I need to filter the records that are between the date '2019-06-26 00:00:00.000' until today. I…
-
1
votes1
answer38
viewsHow to know which users have a photo in a folder via OPENROWSET?
I have a system where photos are stored in briefcase and not in the database. To save the photo file, the system uses the following standardization: Username: Otávio Augusto | Primary Key: 12345…
-
1
votes1
answer70
viewsHow to show certain amounts of lines?
I have a query that takes the highest sales values of a given product per year . The query follows this structure : select ano , descricao, sum(valor) as valor from produtos group by descricao, ano…
-
1
votes0
answers45
viewsError in SQL SERVER PIVOT
Guys, I have a problem in the structure of my PIVOT. DECLARE @IdGiaContribuinte INT = 0, @IdGrupoContribuinte INT = 0, @Exercicio INT = 2017, @IdVafvalorAdicionadoTipo INT = 3 SELECT U.Exercicio,…
-
1
votes0
answers52
viewsGroup information with a common variable in PHP + SQL SERVER
I am developing a code where I have some related tax notes for a user ( unique id ) and when you take the information comes me several lines with the user name and the corresponding tax note ,…
-
1
votes0
answers400
viewsImport CSV File to SQL - Delphi
I have a program in Delphi that imports certain CSV file to an SQL database in order to later compare the data between different versions of the same file, for example a version of the file is from…
-
1
votes2
answers87
viewsSQL Server Charindex Problem
all right? I find myself in a dilemma regarding the use of Charindex from SQL Server. However, I need to read a table field where the address and number are only separated by a blank space. I…
sql-serverasked 5 years ago Sergio 33 -
1
votes1
answer57
viewsError executing a subquery in sql server
I am trying to return values where the date is between two fields of my page this field and max(field) This is the consultation: SELECT COD_SECAO , SECAO , CHAPA , NOME , DTNASCIMENTO , DATAADMISSAO…
-
1
votes1
answer1364
viewsSQL Server - Incorrect time in GETDATE (Timezone) function
I have an SQL Server running on AWS, since yesterday the function GETDATE() has been returning the time with an extra hour as if it were in the time zone -02:00. I have checked on Linux that the…
-
1
votes2
answers420
viewsThe Datediff function resulted in an Sql Server overflow
I have the following appointment: SELECT ISNULL(MAX(CONVERT(TIME(0), DATEADD(SECOND, DATEDIFF(SS, [INICOLIGACAO],[FINALLIGACAO]), 0))),'') AS [DURACAO_CHAMADA] WHERE CONVERT(DATE,[DIA]) =…
-
1
votes1
answer41
viewsConcatenate with specific format
I need to concatenate two columns, a year and a month, but still keep a number of characters limited to six. And when the month is less than 10 the output brings the concatenation but only with 5…
-
1
votes1
answer303
viewsSum of two floats with 2 decimal places resulting in 4 decimal places in JAVA
I am having a JAVA problem where I want to store calculation results with only 2 decimal places in SQL Server. For that at the end of my calculations I perform: Math.round(valor * 100.0f) / 100.0f;…
-
1
votes0
answers133
viewsSave 3 decimal places to sqlServer
Personal I have to save 3 decimal places in my database SQLSERVER, however this saving only 2 houses for example I have a value 0.456 and when saving is 0.450 in the code : using…
-
1
votes1
answer223
viewsHow do I create an alert through a Trigger by not blocking the Insert?
Guys, usually whenever I create a Rigger is to perform insertion blocking or only update values. But this time I just need the system to alert not stopping the person performing the document…
-
1
votes1
answer625
viewsHow to use CASE in a Where clause
Hello, I have the following script situation: SELECT * FROM Formulario WHERE DataInclusao = '2019-10-28 08:19:54.000' AND chave = 'XXXXXXX' AND Id = 2 This table has a column called Productoid, in…
-
1
votes1
answer223
viewsHow to run a MERGE object list by returning the Update or Insert Id?
I have the following scenario; I need to make a INSERT or UPDATE from a list of List<PRD_ARTIGO_VARIANTE_VALOR>, my doubt is whether there’s any way I can get past the list of a single time by…
-
1
votes1
answer60
viewsInsert not exist duplicating records
tou with a problem in SQL server 2008 I have to enter an occurrence of the credit card data however the query is not taking place the way I needed. The tables are CREATE TABLE TEMP_DADOS_CARTAO (…
-
1
votes1
answer90
viewsSQL Server - Return only the searched word
I have a problem where the Cód. below returns not only the searched words, but tb words that have this word in their composition. Ex: The term is Rio, but also finds terms as salary. In the link…
-
1
votes0
answers135
viewsDate value coming 01/01/0001.00:00:00
I’m having a problem with my API when I try to rescue a date from a column in my table in Sqlserver I’m doing it this way using (SqlCommand command = new SqlCommand()) { command.Connection =…