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
answer326
viewsProblems with external SQL Server connection in PHP
I am with a problem for days with an external connection PDO sqlsrv, I have scanned the internet and I did not find a solution. I installed all sql server drivers for PHP, including, I installed sql…
-
0
votes1
answer321
viewsDROP permission of tables in SQL Server databases
When executing the (T-SQL) DROP command below in SQL server the following message is displayed: Cannot drop the table '[dbo]. [TABLE]', because it does not exist or you do not have permission.…
-
0
votes2
answers299
viewsHow to use a variable to delete with like? SQL Server
I’m having trouble developing the T-SQL below: DECLARE @NOME_FILIAL VARCHAR(25); DECLARE @DATA_AJUSTE DATETIME; SET @NOME_FILIAL = (SELECT FILIAL FROM FILIAIS WHERE COD_FILIAL='125518'); SET…
-
0
votes0
answers144
viewsHow to save data from a column and then overwrite it again? SQL Server
I need to save data from a table to a database command and return that data to the same table after a while... I thought I’d do something like this: DECLARE @NOME_FILIAL VARCHAR(25); DECLARE…
-
0
votes1
answer63
viewsHow to convert a function to view
Good afternoon, I have the following function: if object_id('dbo.batidas', 'TF') is null begin exec('create function dbo.batidas() returns @retorno table(T int) as begin return end'); end; go alter…
-
0
votes2
answers46
viewsInsert records that only exist in the source table with MERGE
I created the following script that only inserts records that do not exist in the table teste_tb_planos_acoes, put some conditions: If the column value designacao exists in the table…
-
0
votes2
answers972
viewsHow to Use an UPDATE within IF ELSE SQL Server
I’m trying to verify if a column exists within a certain table. When checking if it exists, I want to update the column with the value 1, if not, create and update. However, every time I run the…
-
0
votes1
answer109
viewsPIVOT after execution the message is "Incorrect syntax next to the keyword 'FOR'."
I need my data to return customer information by courses in a single row, that is, the various different courses done instead of coming in individual rows need to appear in new columns in the…
-
0
votes1
answer387
viewsBank Consuming all memory
Good day I am with a problem , users of a given system are having problems when consulting a name in the system "a simple search" I joined the bank and noticed that in sql there are several banks…
-
0
votes0
answers28
viewsDeleting records from a very large table
We have a table on Sqlserver with over 154 million records and we need delete all records whose DTANO is less than 2017. But the bank is accessed via WEB and, of course, can not get stuck. Trying to…
-
0
votes3
answers1009
viewsHow to make a Useful days rule in Asp.net and C#?
good afternoon I am wanting to create a billing email sending rule that when there is a holiday he considers the next day and if it is Sunday he performs the task on Tuesday. Today the system uses a…
-
0
votes2
answers189
viewsHow to locate information by considering a range (range of numbers)
In the company where I work we are automating the process of calculating variable remuneration, and for this we are transposing all the logic that was in the EXCEL to the database. However, I’m…
-
0
votes2
answers362
viewsHow to connect PDO with named Sqlserver instances?
I can’t connect PHP 7.0.36, sqlsrv PDO drive on Ubuntu 16.04 on SQL Server 2012 when the database has a appointed body. When do I use the standard instance works. $conn = new…
-
0
votes1
answer59
viewsPIVOT - Difficulty with Columns
Considering the table: CREATE TABLE [dbo].[VENDAS]( [VENCIMENTO] [datetime] NULL, [VENCIDO] [decimal](18, 0) NULL, [RECEBIDO] [decimal](18, 0) NULL ) ON [PRIMARY] INSERT INTO VENDAS…
sql-serverasked 5 years, 3 months ago Junior Moreira 7,299 -
0
votes1
answer112
viewsADO fails to connect
I have a project in Excel where I am trying to make a connection to SQL Server database. I am working on a virtual machine and the database is on another machine, however they are all on the…
-
0
votes1
answer427
viewsSeparate results from an SQL query by date
I am creating an SQL query that will be used in a system/report and came across the following problem. It has two results, one that displays the total time between the days searched and the other…
-
0
votes2
answers309
viewsHow can I only enter a certain amount of records into sql server?
I have a table called Hoteis which is related to another helper table Hoteis_Fotos, as its name suggests this table will save the photos of a particular hotel. As you may have understood, each hotel…
-
0
votes1
answer111
viewsProblem in creating a stored Procedure
I am trying to create a stored database that serves to check if my table is empty, and if it is not returning the value with the higher Id. But I’m not getting it. CREATE PROCEDURE spConsulta…
-
0
votes2
answers1109
viewsInsert error: There are more Columns in the Insert statement than values specified in the values clause
When I give an input searching data from another table, this error is returned, which may be wrong with the query ? INSERT INTO dbo.CRMRAT (IDCRMRAT, CODCOLIGADA, STATUS, TIPO, IDCRMCLIENTE,…
-
0
votes1
answer257
viewsHow to take all values of a select and run in a Procedure?
How to take all the values of a select and play in a precedent to give an Insert without running one value at a time? I have the following sql code: --drop table #tabelaEntSaida; --drop table…
-
0
votes1
answer165
viewsProblem with read Property 'query' of Undefined
I’m having trouble getting the result of a query in Nodejs bd -Sqlserver module - mssql Error presented: Typeerror: Cannot read Property 'query' of Undefined At formulasdao.getFormulas (C: xampp…
-
0
votes0
answers168
viewsProblem to run select with sequelize
I’m having trouble executing a select in Nodejs where it takes quite long looking that the same stays in infinite loop. module - sequelizejs bd - SQL server dbConnection const Sequelize =…
-
0
votes1
answer113
viewsSql Server Procedure
I have the following description PROCEDURE [dbo].[spAVL_Ignition] @DeviceIMEI VARCHAR(50), @TimeStamp SMALLDATETIME, @Value INT, @Tag VARCHAR(50) AS BEGIN IF NOT EXISTS (SELECT TOP (1) TimeStamp…
-
0
votes1
answer86
viewsQuery [SQL Server] Aggregate field with equal values of a later date and bring other attributes referring to that date
I would like to help to assemble a query to aggregate the same phone numbers and bring the latest date, in addition to bring other attributes referring to that date in SQL Server. I built this query…
sql-serverasked 5 years, 3 months ago Hugo Baur 1 -
0
votes1
answer69
viewsProblems in select using Having MAX non-boolean expression
I need to make a select to pick up all the patients who have been consulted over a period of time in a specific sector, and see when their last comeback was, and if they are more than a year old not…
-
0
votes1
answer110
viewsGenerate Unico Code in Sequence without Repeating MVC
I want to generate a registration code for each registered client. As ID I use the GUID, however, it is for ID(as it is extensive), I need a small code, not just a digit, for example: cód: 0001 , It…
-
0
votes0
answers25
viewsI can not fetch information from a MS SQL database through ODBC and with Codeigniter query Builder
Good, I am trying to create a login page with Codeigniter. It turns out, to validate the entered data, I need to fetch information from a MS SQL database through ODBC. When using the Codeigniter…
-
0
votes1
answer917
viewsMerge two queries in SQL Server
Hello, I have two queries of the same table, but I’m not able to join them parallel, I tried to use the UNION, but it didn’t work, is there any way to do it? Or else create a column with the…
-
0
votes1
answer48
viewsAdd values with different codes
good evening, I have the script below: SELECT Month([doacao_total].[doacao_sdt_data]) AS MES, Year([doacao_total].[doacao_sdt_data]) AS Ano, Sum(doacao_total.doacao_mon_valor) AS [Valor_doacao],…
-
0
votes0
answers20
viewsDoubts about Stored Procedures
Good Afternoon, I have a Stored Procedure, the purpose of it is to insert the data from a Mirror table and not bring repeated Id’s, as it has a robot that does data extraction and inserts in the…
-
0
votes1
answer62
viewsSQL execution pouch while executing another program in transaction
I created a program that accesses my database in transaction READ UNCOMMITED. _oConn.BeginTransaction(IsolationLevel.ReadUncommitted, _transactionName); Everything that runs within that transaction…
-
0
votes0
answers55
viewsEfficient SQL Server Index
Ladies and gentlemen. (as), I need help to build an efficient index for an SQL table. I have a table that is causing me a certain headache, because it is consulted with a certain frequency, besides…
-
0
votes1
answer981
viewsGrouping data by hour intervals in SQL Server
I currently have the following query in the SQL Server database: SELECT TOP 5 CAST(CAST(CAST(CAST(E3TimeStamp as float)*24 as bigint) as float)/24 as datetime) as hora,…
-
0
votes1
answer51
viewsHow to select two Columns with Different values when the ID Matches
Let’s Say I have 1 table (1) with the users info. A table 2 with users plans. I need to select each users plan and show on the same line in case he’s got more than 1 plan. TABLE 1: +------+------+…
-
0
votes1
answer49
viewsPurge invalid data before creating a Foreign Key (FK)
I’m working with a database bequest where there are 3 tables: Tabela A, Tabela B and Tabela C which stores the relationship between Tables A and B, however when the bank was created the Foreign Keys…
-
0
votes1
answer66
viewsField cumulativity calculated using Sqlserver
I have the following table: Therefore, I need to accumulate the value of the expression using SQL Server and the only way I could do it was using cursor; someone has another idea? USE TEMPDB GO IF…
-
0
votes0
answers42
viewsRelationships using OPENDATASOURCE function
I need to list a table from one server and a view from another. I researched the function OPENDATASOURCE and later implemented it in the query. When executing, the program returns this message to me…
-
0
votes2
answers893
viewsValidate data in sql server
I get a date, and I need to know if it’s valid, if it’s not, I need to shorten her day until it’s valid. set @data = (select…
-
0
votes2
answers314
viewsReturn last entry of each product
help me. I’m in a situation where I want to bring only the last note entry of each product to create a report. I created a select, but there are products repeating where they shouldn’t. See select:…
-
0
votes2
answers519
viewsSQL Query average time DO NOT take into account Weekends and holidays
I need to average the time it takes since creation (a. Date of creation) until completion (s. Data_status_finalized) field. Not able to count weekends and holidays. The following query is working,…
-
0
votes3
answers279
viewsuse of cursor to update item to item stock
I have a bank where the stock(onhand) must be changed each time an order(docentry) is made, whether it is a confirmed order or not, for that I need to download the order quantity(Qty) with a simple…
-
0
votes0
answers442
viewsMust declare the scalar variable "@doc"
I searched a lot about this error but nothing seemed similar to what is happening to me, I created a cursor and after fetch next returns me the title error, someone could help? declare @doc int…
-
0
votes1
answer42
viewsHelp in this query in SQL Server
That consultation: SELECT C.CompanyName, MAX(SOH.TotalDue) AS Total, A.CountryRegion FROM SalesLT.SalesOrderHeader SOH INNER JOIN SalesLT.Customer C ON C.CustomerID = SOH.CustomerID INNER JOIN…
-
0
votes2
answers66
viewsHow to "reset" the other SQLSERVER line
I have a query that returns to me how much particular customer bought from a certain product. The problem is in the item(product) because it has more than one feature that causes duplicity in the…
sql-serverasked 5 years, 1 month ago PAULO RAFAEL 1 -
0
votes2
answers406
viewsSelect 2 latest records from Sql Server table
I have a table with the following fields. IMEI | TimeStamp | Value 123 | 1570011000| 1 123 | 1570012800| 0 123 | 1570015200| 1 123 | 1570017000| 0 I would like to take the last 2 records and make…
-
0
votes1
answer113
viewsstore select result in a table
Good afternoon I have the following query SELECT +cast((DATEDIFF(SECOND,r.start_time,GETDATE())/60)%60 as varchar)+'m ' duracao ,isnull(s.login_name, s.original_login_name) AS LOGIN ,r.session_id…
-
0
votes1
answer52
viewsI want to display a value according to the current date
I want to select the amount of Num_CP according to the current date, so I am using the function GETDATE(), but my SQL points out the following error: Only one Expression can be specified in the…
-
0
votes1
answer39
viewsProblem sending image to database
I have a web application in which the user can change his profile image, I am able to select the image file correctly, the problem is time to send to the database (send the application data to a…
-
0
votes0
answers53
viewsError inserting data in table with column of the numeric type VB NET
Hello, I am having problems when trying to insert data in an SQL database through VB.NET. I’m migrating some vb6 projects to . net, I came across the first problem I spent the day trying to solve…
-
0
votes1
answer92
viewsHow to perform multiple database insertions
I am a beginner and I have a code in which I need to insert multiple products inside a shopping list, however, in the code I made, it is only possible to insert one JSON at a time. [HttpPost]…