Most voted "tsql" questions
T-SQL (Transact Structured Query Language) is the extension of the SQL functionality supported by the Sybase ASE and Microsoft SQL Server databases. There are differences between language versions, so questions about T-SQL should be marked appropriately with tag [sql-server] or [Sybase], and include the version as well.
Learn more…107 questions
Sort by count of
-
1
votes1
answer437
viewsLogical deletion of SQL Server records
We have the culture of making only logical exclusions in the application, keeping 2 fields where 1 is the date of exclusion and another char that gets’S' or 'N'. When we perform searches for deleted…
-
1
votes2
answers437
viewsSorting in recursive query
In another question I asked i had found a solution but ordering only works if the ID’s are growing: USE TESTE GO WITH Niveis AS ( -- Membro âncora SELECT Id, IdPai, convert(varchar(1000), Nome) as…
-
1
votes2
answers100
viewsDynamic TSQL for multiple returns
I need to make multiple inserts that will depend on an existing result in a table like this: --CRIA TABELA #CONTATO CREATE TABLE #CONTATO( NOME VARCHAR(100) NULL, TELEFONE VARCHAR(50) NULL );…
-
1
votes0
answers26
viewsCreate Partition
I’m sharing a table in my database, I created Function Partition and Scheme Partition. But when I go to Create Partition Wizard the Radiobutton Existing Partition Function gets disabled even with…
-
1
votes1
answer47
viewsHow should the data of a table be selected through junctions?
When using the SELECT to obtain data from tabela_A by making a junction with the tabela_B, normally, and believing it to be the correct form, we use some of the commands JOIN. Ex: SELECT codigo,…
-
1
votes2
answers11627
viewsConvert "hh:mm:ss" to int minutes
I have the following function that calculates the hours 01:00, returns 60 minutes. but the column of sql store in time(0 format) 01:00:00, What error in my function, I do not know how to increment…
-
1
votes2
answers509
viewsCapture values from one table and insert them into another
I have a temporary table that fills it with the result of a particular query. Now I need to go through the data of this temporary table, row by row, and take certain fields and insert them into…
-
1
votes1
answer116
viewsCreate select to return last time something was non-zero
I have a table called Estoque, where have the columns NOME_PRODUTO, DATA, ,among others. The idea is that when I make one SELECT Using the date as parameter I return all products I had in stock that…
-
1
votes0
answers252
viewsHow to make multiple mask Replaces per table field with T-SQL
I am performing some texts (Mask) Replaces from a field of a temporary table. I am substituting where there is the text searched for a field of other tables. Example: SELECT TOP 1000 * INTO…
-
1
votes3
answers1195
viewsConvert nvarchar(50) field to SQLSRV table datetime
I need to change a field in the SQL database table whose format is in nvarchar(50) and data were saved in date format 07/09/2017, containing values NULL also! I need to convert this field directly…
-
1
votes1
answer648
viewsImport MS Access data to Sql Server via code
I need to import data that is in an Access database via Sql Server code. My software that is made in C# for many years has been integrated into an Access database. From now on we are migrating to…
-
1
votes2
answers1338
viewsT SQL Merge Two Lines in One
I have a common id (103307) and would like to join two lines in one. From image 1 and leave as image 2. It is possible?…
-
1
votes1
answer1067
viewsDifference between hours and minutes days in Sql Server?
I got two columns like datetime. I have tried in many ways to catch the difference between them, but the number of days is always incorrect. Example: Data1: 2018-01-17 17:00:00 Data2: 2018-01-18…
-
1
votes2
answers1084
viewsHow to make a dynamic update to all database tables for a specific column
Personal how can I make a dynamic update to all database tables for a specific column common to all my tables? I’m thinking of using the catalog table to pull objects from the database but how can I…
-
1
votes0
answers166
viewsStoredprocedure in SQL-Server passing a C#List parameter
I would like to pass a list of parameters to a precedent, how to do this process? I did some research and I thought it is possible to create a TABLE TYPE and use it in the parameters of the past,…
-
1
votes3
answers113
viewsSQL Server - Query logic
Note 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,…
-
1
votes1
answer212
viewsT-SQL - Delete filter "NOT IN" does not work
I am filtering my base by store code (varchar), but the filter is not removing the store codes I want to delete from my query. This is my consultation: SELECT A.CPF , A.[Cod Loja] , B.NomeLoja ,…
-
1
votes2
answers169
viewsHow to Make a Scan in SQL
| cliente | id | cpf | cpf_valido 2 | 1234 | 1 3 | 1234 | 1 5 | 4567 | 0 and I need to set up the table like this | de_para | id | id_para | cpf 2 | 3 |1234 3 | 3 |1234 5 | 5 |4567 To summarize,…
-
1
votes1
answer51
viewsFilter query by removing duplicates
Good afternoon, I’m with the following select: select codemp, codfunc, codevento , vlrevento from sankhya.TFPFOL where codemp = 1 and codfunc = 26 and month(referencia) = 1 and year(referencia) =…
-
1
votes0
answers44
viewsSql Server Function - 0 hours today to the current time
Please select the amount of hours in regression until 00:00 hours in Sql Server, always of the current day. I get this through a function like 'DATEADD'? Ex: Now it is 15:00 hrs would like to pick…
-
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
votes0
answers51
viewsCustomer SELECT with payment for the last two months (60 days)
I have a TBCLIENTS table where I have the columns: NAME, DATA_PAGAMENTO, FORMA_PAGAMENTO. I need to know the customers who paid in the last 2 months (60 days) in the form of payment BOLETO. How I…
-
0
votes1
answer2862
viewsHow do you check if a view exists before you have it created?
Take as an example the following view: 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…
-
0
votes1
answer106
viewsSubquery 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 passes straight, and she is in Loop…
-
0
votes3
answers204
viewsOrder by or filter in Sql Server
It’s possible to use order by or some filter in Ner Join or left Join or I’m trying to do it wrong. I need to bring in a query a column that is in a daughter table, but I need it to be the column of…
-
0
votes1
answer63
viewsINSTEAD OF (Deleted table)
I’m having trouble creating this Rigger: CREATE TRIGGER TGmonitoraClientes ON TB_CLIENTES INSTEAD OF DELETE AS BEGIN UPDATE TB_CLIENTES SET clienteAtivo = 0 FROM TB_CLIENTES WHERE CODcliente =…
-
0
votes1
answer373
viewsI need to display a TOTAL field in a PIVOT query
I have the query below that returns the total quantity in stock of the products for each city. Each city is a column and products are displayed in rows. Now I need to display in a field (column) the…
-
0
votes1
answer40
viewsError trying to create a Proc in the bank
I’m trying to run a stored procedure in the bank and it’s giving this message: Cannot Grant, Deny, or revoke Permissions to sa, dbo, Entity Owner, information_schema, sys, or yourself How do I fix…
-
0
votes3
answers69
viewsI have this cursor and the Where 'between' gives error. I wanted to select the years 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…
-
0
votes2
answers322
viewsProcedure delete Join between tables
Good afternoon, I have the following Tb environment.Client where a client has N processes in Tb.Process, N movements in Tb.Progress and N attachments in Tb.Annex. I need to mount an sql statement…
-
0
votes0
answers465
viewsProblems with OPENROWSET in SQL Server 2016 Express (64bit)
Good morning, I’m trying to read an Excel file . xls by the OLEDB driver used in SQL Server for integrations with Microsoft.ACE.OLEDB.12 files. 0 in SQL Server 2016 Express (64bit). Using command…
-
0
votes0
answers127
viewsCompare values of two tables in a Procedure
I have an application that lists in a grid files that are registered in the table Scf_documentprocessocompra However, now I need to list only if this file also exists in the table SCF_ARQUIVO_UPLOAD…
-
0
votes1
answer425
viewsIs there a difference in performance between INNER JOIN and CROSS APPLY?
I am starting studies on SQL SERVER and some places teach to use the INNER JOIN to make the junction of two tables. However, there are some other places that teach via CROSS APPLY.…
-
0
votes2
answers55
views -
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
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
votes2
answers184
viewsHow to automatically name a manually created CONSTRAINT in Sqlserver 2016
Hello, I am creating a database and need to create some compound Index to optimize the bank processing. The problem is that I don’t want to have to name these Indexes one-on-one. Normally, I create…
-
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
answers21
viewsHow to verify and manipulate native LOG in Sqlserver?
I am working in an application generating a Batch service being developed in T-SQL. Just like Mysql and Postgresql have their LOG files, where are these LOG files in Sqlserver? Another question is…
-
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
answers13
viewsAccess the SSIS catalogue via SSIS
I need to create a process on SSIS SQL Server Integration Services that can extract from each project which tables are being used. The end result is to get a table that is automatically fed with two…
-
0
votes1
answer302
viewsWhat is the SQL Server compatible command for Mysql SHOW CREATE TABLE?
What would be the command in SQL Server to view the script for the creation of a given table? With a result more or less like this: +------------+---------------------------------------------------+…
-
0
votes1
answer158
viewsSwap subselect with Oin
good morning! I’m sorry if explanation is not totally clear, it’s because I’m starting in SQL. How do I replace subselect with some type of Join? Because subselect takes longer to load. Examples:…
-
0
votes0
answers96
viewsThe column '<column name>' is invalid in the selection list because it is not contained in an aggregation function or in the GROUP BY clause
Hello! In the system there is data collection for some questions and the answers are 0-100. My database has the following tables: Person, Question, Personal. I’m trying to get a select where to…
-
0
votes1
answer39
viewsInserting data with a proc in SQL Server
I need to use a procedure that adds data to the table Pedido and then on the table ItemPedido automatically. But I’m not able to create a Procedure work. Follow my code below: create procedure…
-
0
votes1
answer39
viewsPlot Pivot (Row in column)
Gentlemen, good morning ! I am trying to make a simple parcel PIVOT under same customer number (330162210001), however I am not getting... The idea is that each plot result found is a column. We…
-
0
votes2
answers790
viewsHow to get max() and min() data in SQL?
How can I get the minimum and maximum date of a table? I am using the functions min() and max(), but it is not returning the expected value. This is a small example of the date data from my table:…
-
0
votes1
answer31
viewsHelp with SQL query - delete a field/ occurrence
I am trying to perform a query where all beings should be managers but they should not have worked on a project. It turns out that this john is the only being who works and manages a project and I…
-
0
votes1
answer27
viewsstatus of a record in a given date range
Greetings! I came across a problem and I’d like some help if that’s possible. I am developing a financial report and in this report I need to get the status of a title in a certain period. For…