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
answer1021
viewsConsultation with MAX(DATE)
I am trying to generate the query below as follows. Cliente Tarefa Data da Ultima Providencia Teste 16555 04-07-2017 However, is generating duplicate, IE, I want to take the last date of the last…
-
2
votes1
answer76
viewsExtract free text field dates
I am running a query in a view, but one of its fields is text, in this field the user can inform a date (xx/xx/xxxx) as well as any other information of type text. I wonder how I can return only the…
-
2
votes1
answer1371
viewsdecimals of a variable Numeric field depending on CASE in SQL
I have a query where, depending on a parameter, I need the result in a field to be 5 decimal places or 2 decimal places, this is possible in SQLSERVER 2008? Example DECLARE @VALOR DECIMAL(18,2),…
-
2
votes3
answers7703
viewsRemove last number with sql
I would like to take the last paragraph 1 from this sequence: 0495747500000049908275289000100040000000041 How do I do in sql server?
-
2
votes2
answers335
viewsHow to return a special character to a query
Good morning! It may be simple my question, but I am starting in SQL Server still, so I would like to know how to return in select a special character. As you can see, there is a simple quotation…
-
2
votes1
answer743
viewsHow not to bring a particular column in SQL using IF and ELSE?
Gentlemen, I have a table where I want to bring the column when the value is null but when it is filled it should not be displayed, as I can implement this condition in SQL ? SELECT OBS.NUOBS,…
-
2
votes2
answers229
viewsHow to use the WHERE clause on top of a column made from row_number() over()
I’m trying to use Where on top of a column generated by row_number but it doesn’t work; it’s possible to do this?
-
2
votes2
answers113
viewsJoin Tables for Tableau
I needed to create an extract for a Tableau report, where my team developed the database and the web system and another company developed the Table report. This is the scheme of the problem To feed…
sql-serverasked 7 years, 1 month ago Maurício Pontalti Neri 133 -
2
votes2
answers569
viewsSplit a query
I need some help from you guys, i have a query on my system, which has 4 cases SELECT TOP 3 * FROM ( SELECT Title, SUM(Count) AS Count FROM ( SELECT CASE WHEN EstadoId = EstadoIdAutor AND EstadoId =…
-
2
votes2
answers700
viewsQuery with Left Join without returning duplicate value
I have the table tableA and tableB. I’m making a select of all fields of both tables joining the same by left Join select * from tableA left join tableB on tableA.id = tableB.id But the relationship…
-
2
votes1
answer214
viewsLinked SQL Server and Firebird: Error 'Must declare the scalar variable'
I made a Linked of my SQLSERVER with the FIREBIRD. But when I pass a variable inside the query to return the amount of record I get the error: Message 137, Level 15, Status 1, Line 1 Must declare…
-
2
votes1
answer128
viewsError using Code First From Database
I’m trying to use the Entity Framework with a Sqlserver database that I created outside of Visual Studio. The problem is that when I add the ADO.NET Entity data Model to the project to do the…
-
2
votes1
answer55
viewsIs it possible to "Group by" by column content?
I was wondering if it was possible to use GROUP BY based on the date of a column, in this case the column ANALYSIS that creates groups whenever it finds 0, instead of the column. DIA MES YEAR TODAY…
-
2
votes2
answers711
viewsINNER JOIN + LEFT JOIN
I’m trying to make a query where the data lies in 4 tables: TAFCBHISTPED = NUPED, DTEMIS TAFGRPROD = CDGRPR, DSGRPR TAFPROD = CDPROD, CDGRPR TAFITHISTPED = NUPED, CDPROD, QTPED My query stayed that…
-
2
votes2
answers161
viewsUpdate in three tables
Good morning, I wonder if it is possible to update in three tables at once? I have the A, booklet, booklet, which are listed by the id_book column, and I would like to change the value of the book…
-
2
votes1
answer3058
viewsSQL distinct with sum
Hello, I have a problem making a sum in a query. Example and query results: select DISTINCT t.ID, t.nomeuc as "Nome UC", t.tipoturno as "Tipo Turno", a.num_presencas as "Número de Presenças" from…
-
2
votes2
answers320
viewsList tables in a single SQL Server query
I need a query that returns to each map the players who had battles on it, the amount of battles each player had (on the respective map), the total time played (per player on the respective map),…
sql-serverasked 7 years ago Roberto Gomes 455 -
2
votes1
answer90
viewsSQL command in C#
Well I’m doing a crud using mvc and Entity framework, only I don’t know how to pass parameters... here’s my code public void Cadastrar(TimeModel timeObj) { strQuery = "INSERT INTO TimeFut (nome,…
-
2
votes2
answers1233
viewsDate Working Hours - SQL Server
Guys, I have a question. In the query below, in the tarexpiration field, he is counting the hours normally, however, I want to count only the working hours. NOTE: Already has a useful hours function…
-
2
votes1
answer235
viewsPick up day of the week in a select
I need to know how to get inside a select (with LEFT JOIN, INNER JOIN) take the day of the week from a field of a table, compare and see which day of the week, if it is 1 add 2, if it is 7 add 1?…
-
2
votes2
answers840
viewsUpdate in a column using more than one return
I have to update a certain field of a table by subtracting from it the values returned from a select in another table. The problem I’m facing is that as select returns more than one value and I have…
-
2
votes2
answers74
viewsTyping
I am creating a database and in it has a field that receives a date, I would like it to appear only the date. If I use the type datetime comes with the time too. And in SQL Server you have the type…
-
2
votes2
answers171
viewsDelete and relocate index
How should I associate data to have a db SQL Server 2017 with a good performance. I am doing a data association and being new in this area I feel a little lost. I have the following structure as an…
-
2
votes1
answer217
viewsUse Datepart as Query parameter
I’m developing a system and I’m bumping into an SQL query that consists of the user searching for Date and will have the option to choose if the query will be made adding Weekend to these dates,…
-
2
votes2
answers1443
viewsGROUP BY with 2 tables
I need to make a select with JOIN in two tables but I am not able to group to not repeat the lines. Follows the expression SQL: SELECT Andamento.NumeroProcesso, Andamento.Chave, Andamento.Codigo,…
-
2
votes3
answers1491
viewsHow to use alter table by modifying an attribute to PK and FK?
I have a table Funcionário, where your PK that’s the one Cod_Func. Then I created this table Vendedor, created the attributes manually, did not put the Cod_Func table Vendedor as PK, because this is…
-
2
votes1
answer142
viewsRatio 1:N check date, difference 6 month
I am developing a SQL Server Database, which lists two tables: Where a process has N movements, I need to return the following data: all Process that have the column Irrecuperavel(int) = 1 and that…
-
2
votes2
answers428
viewsHow to make a query that brings only the count of an uninterrupted sequence?
I want the counting of uninterrupted values of the current year backwards, until the first occurs NULL. Example: Several people make donations to an NGO annually and this is stored in a database,…
-
2
votes1
answer820
viewsReturn int in a select using Dapper.
I need to return the idCity. If it is not found in one table, it is obligatory in the other. The return is nil. My Query public const string sql = @"DECLARE @retorno AS INT = 0; SELECT @retorno = id…
-
2
votes1
answer279
viewsEXCEPT equivalence | INTERSECT & exists | not exists
Would be the EXCEPT | INTERSECT always equivalent to a not exists | exists? Having the following consultation SELECT ProductID FROM Production.Product INTERSECT SELECT ProductID FROM…
-
2
votes1
answer75
viewsHow to add a description in the column?
I am using Firts Migration to update in MS SQL SERVER Database. In class ApplicationDBContext, has a method OnModelCreating where you can rename table, change data type, set your keys, etc... In…
-
2
votes1
answer65
viewsString Connection to access sql remotely
I have an SQL SERVER database on one desktop and I’m making a program on another PC that will access that database. I wanted to know how to mount my string Connection to access the database…
-
2
votes1
answer260
viewsSQL Server Binary File
how do I download images, content, files that are stored directly in the database in binary form? I ask this, because I am in a data migration and the layout (spreadsheet in excel) of the new system…
-
2
votes0
answers63
viewsUpdate table with XML field and in different databases
I have two banks SQL SERVER 2012 installed on server A and server B, I need to insert and then make a Update in the server table B via linkedServer by the A server, but these tables have fields XML,…
-
2
votes1
answer223
viewsThe Object 'XXXX' is dependent on column 'XXXX'
When I try to change the type of the primary key of a table, I get the following error: The object 'XXXX' is dependent on column 'XXXX'. I would like to know how to "less" manual fix this error…
-
2
votes1
answer223
viewsLivechart - Fill Cartesian Chart with Sql Server Query Data
I have a Datacontext set in a Cartesianchart which does not display the data... no error is displayed, just think I’m making wrong use of the Datacontext and I can’t fix it, I’m using the package…
-
2
votes0
answers186
viewsHow to list all parameters of a report automatically in SSRS?
Problem I need to generate a report usage log with the user, report name, usage date and selected parameters. Most of the fields were obtained using the Built-In Fiels. However, I cannot get a…
-
2
votes2
answers304
viewsTriggers INSTEAD OF Update, How to filter by date
Hello, First of all thank you for all your time in the community. Come on! I will throw the information and then try, in the best possible way to explain the problem. I have 3 tables: Person List…
-
2
votes1
answer293
viewsUse select top to declare a variable
I wanted to assign the value of the last item registered in the table alu_cod, but the query returns me error after the @total =: declare @total int select @total = SELECT TOP 1 * FROM Alunos ORDER…
-
2
votes2
answers280
viewsSelect from 3 related SQL Server tables
Good, I have the following 3 tables: SELECT * FROM Cartao INNER JOIN Registo ON Registo.ID_Cartao=Cartao.ID_Cartao INNER JOIN Clientes ON Registo.ID_Cliente=Clientes.ID_Cliente WHERE…
-
2
votes2
answers720
viewsSQL SERVER | Fill empty fields in select
I have a select in a table: select a.linha, a.NUM_LCTO, a.DT_LCTO from arquivo a order by 1 That returns me the values as follows (I put only a few lines, the total result is about 800000 lines.):…
-
2
votes1
answer394
viewsChange the type of a column in several tables in SQL Server
I have a database with 41 tables, in all tables I have a common column to which I would like to assign another dataType. In my case the column is currently varchar(255) and would like to change to…
-
2
votes1
answer168
viewsWhat is a static table in SQL Server?
What is a static table in SQL Server? I can’t understand this concept by internet searches.
-
2
votes2
answers1707
viewsTable structure in user questions and answers template
I have a doubt in the structure of some tables and I hope you can clarify in detail below. Setting The system will generate a way to create forms and questions dynamics, in order to be answered by…
-
2
votes1
answer70
viewsWhat kind of data to accept any size?
What kind of data can I use to store text "dynamically" in SQL Server? I know that CHAR and VARCHAR are character data types, the difference is that CHAR is a type of data fixed length and VARCHAR…
-
2
votes2
answers116
viewsHow to return a specific column as an element with FOR XML AUTO clause
I need to make a certain column an element in the return xml when I use the FOR XML AUTO clause. Auto-return transforms all fields into attributes of the corresponding element. All right, but either…
-
2
votes1
answer98
viewsFind missing table number
Have a table with the following structure: ------------------------ Codigo | Num_doc | Serie ------------------------ 1 | 1 | 1 2 | 1 | 2 3 | 3 | 2 4 | 2 | 1 5 | 3 | 1 6 | 5 | 1 7 | 7 | 1 8 | 5 | 2…
sql-serverasked 5 years, 1 month ago Murilo Fechio 836 -
2
votes2
answers80
viewsHello guys. Can anyone tell me why the result of the consultation below is bringing in the first 4 records the Zeroed Balance?
Can anyone tell me why the result of the consultation below is bringing in the first 4 records the Zeroed Balance? I’m calculating the entrances and the exits. Calculate correctly if there are…
-
2
votes0
answers48
viewsHow many bytes has a decimal (18.8)
How do I calculate the number of bytes of one decimal? In my decimal case (18.8). Why decimal (18.8)? A: Because I will save exact values for bitcoin in my BD Recommends a better way than…
-
2
votes1
answer630
viewsConfigure API for SQL Server Database
I have an API that I used with Mysql, but I had to switch to SQL Server. Unfortunately I never used SQL Server, I do not know if you need to download something to get. The API was made in JS. The…