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
answer197
viewsSQL SERVER odd line queries
I need to create query script that returns from the table below only its odd lines, ordered upwards: DECLARE @table TABLE (coluna1 varchar(50)) INSERT INTO @table VALUES…
-
2
votes1
answer533
viewsSQL Select highest value item
I’m using the Northwind database, and I want to select the category that has the largest number of registered items. I was able to list the category ID and the number of products it has with the…
-
2
votes1
answer86
viewsInsert value in column C#
I have to read a column (which is the primary key of a table) and see if there is the value of a variable in that column, if it does not exist, I want to add it, if it exists, I want to move on. I…
-
2
votes3
answers58
viewsSQL Query - Doubt Condition Dates
Guys, good afternoon! I’m having difficulty in the consultation below. I want you to bring all the tasks only when their salary (tarexpiration field) is equal to the month after the opening date…
-
2
votes1
answer6778
viewsThe INSERT statement conflicted with the FOREIGN KEY C#
I have this code to insert values into a table: conn.Open(); comm.CommandText = @"INSERT INTO ArticleBarCode(Code, Code_Article, BarCode, CreatedBy, CreatedOn, ModifiedBy, ModifiedOn, IsDeleted)…
-
2
votes2
answers342
viewsMask SQL Select return
I’m using the following SELECT to return the Ids one-table. SELECT id, duracao_sessao FROM usuario For ID 1 I want the text "Object" For ID 2 I want the text "Class" For ID 3 I want the text…
-
2
votes2
answers7816
viewsConsult in all tables of the database
It is possible to make a query in all tables containing the same column their respective values? For example, I have the Bank called SGE, it has 230 tables, and all these tables have the column…
-
2
votes4
answers2082
viewsCompare a table field with another table
I am trying to create a query in SQL Server to know if the city that was filled in at the time of registration that the person did, is equal to a city field of another table that already has all the…
-
2
votes2
answers1580
viewsImport CSV and convert date in dd/mm/yyyy format to yyyy-mm-dd
I’m a complete beginner in programming, both in Python and Sql, so I have some questions that may seem basic. I get a file. CSV that comes a lot of information not compatible with Sql so always have…
-
2
votes2
answers625
viewsQuery SQL - CASE with LEFT JOIN
I need to create a query that returns all active students and their grades for each subject. If the student has no grade for a particular subject should be returned the student, the subject and in…
-
2
votes1
answer674
viewsAssign a variable a Dynamic Date?
My goal is to create a SQL Server, which has by default two variables, one with the initial date of (hoje - 3 anos) and a final date equal to hoje. I already use for other operations (for example a…
-
2
votes1
answer222
viewsCASE WITH IN does not work
I’m willing to do this search below: DECLARE @codccu VARCHAR(10); SET @CodCcu = '63' SELECT E.codepi, E.numcad, Max(E.datent) AS ENTREGA, Max(E.datent) + P.diaval AS VALIDADE, CASE WHEN…
-
2
votes0
answers37
viewsWhat is the advantage of saving whole in the field that I want to save prices?
I was reading about building RESTFUL API with Laravel, and I noticed an interesting flame that I once wondered if the way I always saved "money" in the database. Is there a problem in saving as…
-
2
votes1
answer1648
viewsHow to assign a EXECUTE SP_EXECUTESQL @SQLSTRING to a temporary table
It is possible in the same script to create a temporary table from an execution like this? --****************************EMPRESA****************************** if(Object_id('tempdb..#TBEmpresa') is…
-
2
votes1
answer64
viewsDoubt in conversion of rows into columns Sql Server 2012
I turned rows into columns and need to improve this query by adding another row in column: This is the query: --****************************EMPRESA******************************…
-
2
votes1
answer482
viewsHow to delete or hide the password entry to access the data of a server with SQL Server from the VBA or Excel macro?
I’m running a database migration service from a server with SQL Server in a company, but requested that I broker the migration in Excel, because they want so in this first phase to advance some…
-
2
votes3
answers2459
viewsDoubt SQL Working Days Query
Good night! Guys, I need to know a following result. I want to bring the working days grouped by month and year from April to June of this year 2017. Example: Ano Mês Dias Uteis 2017 Abril 19 2017…
-
2
votes1
answer6216
viewsJoin columns in one SQL column
I have three columns, belonging to the same table in the database, these being: Growth, Financial Autonomy and Rationliquidity; All columns are bit type. What I need is to group the three fields in…
-
2
votes3
answers186
viewsCrossing of Tables with Multiple Coalesce
Expensive, I have a table of "processes requested for consultation" and two tables with information of registered processes (the "new" processes and the "old" processes). My intention is to bring…
sql-serverasked 7 years, 4 months ago Yuri Camara Batista 43 -
2
votes2
answers5112
viewsWhat is a Dataset and what is its function?
Creating my first database applications (SQL Server), I connect by passing my string and using the Sqlcommand class to pass the query. But searching other sites, I see that access to the bank is…
-
2
votes1
answer14068
viewsConversion from VARCHAR to INT
I’m trying to do INNER JOIN but the fields are in VARCHAR. In a field I have cod_authorization = 749831164 And in the other field I have num_aut = 000749831164 Because of the zeroes "Left"…
-
2
votes1
answer746
viewssplit 1 column into 2 in sql server giving update
I use SQL Server 2012 I have the following problem, in a table there are records of municipalities and two respective Fus but there is the need to divide this column into 2 one of municipality and…
-
2
votes3
answers536
viewsHow to show quantity of sales per month payment in SQL Server
I’m getting the following result: Mes | QtdPorMes 1 | 124 2 | 102 3 | 84 4 | 32 I’d need it to stay that way: Mes | Boleto | Cartão | Total 1 | 100 | 24 | 124 2 | 82 | 20 | 82 3 | 34 | 50 | 84 4 |…
-
2
votes1
answer3680
viewsSQL to count records that have a field with repeated value
Staff I need a Query that does a value count I have in the bank On my system, I have a multiselect that can select more than one option. I wanted a help from you, I never touched with query, I need…
-
2
votes3
answers2216
viewsSQL - Bring only 1 year records back
I’m trying to realize a SELECT that brings me only customers who haven’t bought for 1 year without duplicating the customer. Down with the code I’m trying to: SELECT DISTINCT p.ID, p.Nome_Fantasia,…
-
2
votes1
answer337
viewsError when connecting to Sqlserver C# Web.config database
I’m trying to make an application .NET MVC, but when I connect to the bank is giving the following error: An Exception of type 'System.Nullreferenceexception' occurred in Gerarxml.dll but was not…
-
2
votes1
answer534
viewsIs SQL Express free?
I need a database to use on a Xamarin Forms app for college. I even created in Azure, but the limitation of 32 MB is very large, because I need to store photos too. I searched and saw that has the…
database sql-server xamarin xamarin-forms sql-server-expressasked 6 years, 6 months ago Lucas F. 65 -
2
votes0
answers283
viewsGet Street and number in a string in an irregular expression
I have a table that I have all the address in one column, but it is irregular. Below are some of the occurrences: BR 459 KM 153 RODOVIA ITAJUBA MF KM 05 Rodovia MG353 2Km 55 RUA 37 QUADRA 4 LOJA 611…
-
2
votes1
answer627
viewsOPENROWSET - How to assign a variable instead of the file name to open?
I do this command and I do it right: SELECT * FROM OPENROWSET( 'Microsoft.ACE.OLEDB.12.0', 'Excel 12.0 Xml;Database=\\00.000.00.0000\Arquivos\TI\Arquivos\252203408.xlsx;HDR=YES', 'SELECT * FROM…
-
2
votes4
answers2013
viewsFind the best-selling item along with a particular item
To explain, I prefer an example: I want to find out which item is the most sold along with the salty chicken. For this, I tried the following approach and failed miserably by lack of technical…
-
2
votes2
answers94
viewsAdds WITH query within another query
Guys, how to add the query below as a subconsulta. Consultation with WITH: WITH tabela (projeto, operadora) AS ( SELECT p.projdesc, tt.tartitulo FROM tarefa tt INNER JOIN projetos p ON p.projid =…
-
2
votes0
answers39
viewsCount records that precede the selected one in the sql server, mysql query
I have a question: How do I know how many records you have before a selected value. For example: Select * from cidades where nome= 'SAO PAULO' ORDER BY nome Assuming that the cities table has 500…
-
2
votes3
answers590
viewsHow to remove apostrophes from a variable
I have a text Edit PRODUCT that comes like this: 'STICKER 478', with apostrophes. How do I make it come out like this: STICKER 478 on sql server? I’ve tried that and it doesn’t work: DECLARE…
-
2
votes1
answer2607
viewsChange existing column to Identity
Having an entity where the first key is an integer and the same is defined not to be an Identity public class Teste { [Key] [DatabaseGenerated(DatabaseGeneratedOption.None)] public int Id { get;…
-
2
votes1
answer5466
viewsHow to test connection to SQL Server database
I have an application that connects to SQL Server, but in a client terminal is returning a random error. I wonder if there is a way to test the connection of this terminal with the Sqlserver server,…
-
2
votes2
answers87
viewsI have this query and I’m not able to group by month
DECLARE @Year INT = 2005, @Month INT = 7 SELECT --SequenceNo = ROW_NUMBER() OVER(ORDER BY OrderDate), Year = Year(convert(int,OrderDate,111)), case Month(convert(int,OrderDate,111)) when 1 then…
-
2
votes3
answers2314
viewsHow to calculate two columns and compare the result with another column?
I have a table, where I am bringing two different results with the query below: select sum(qtde_pontos) from dbo.tbl_cc_ponto where re = '9289' and natureza_operacao = '2' and data_lacto >=…
-
2
votes1
answer214
viewsCount and group by day range
SELECT loc.loc_pac as registro, datediff(dd, pac.pac_nasc, getdate()) as 'dias' from loc with (nolock), pac with (nolock), str with (nolock) where loc.loc_pac <> '' and (loc.loc_pac =…
-
2
votes3
answers640
viewsGrouping by day and by date period
I have a query of the period 26 a 30-06 that brings the following result: Data_Cancelado Cancelados 27-06-2017 4 29-06-2017 5 However, I want it to come this way, ie,. Data_Cancelado Cancelados…
-
2
votes1
answer159
viewsProblem when executing a query in a repeat loop on the Mssql Node
So, I am using Node and mssql package (sql-server) to perform queries to my database. however I am facing a difficulty to return queries that need to be executed within a repeat loop. Maybe it’s…
-
2
votes4
answers593
viewsSql - Query of two maximum values
Suppose we have this database codigo, data, valor,seq (1, '2014-01-01', 10,2), (1, '2014-01-02', 20,1), (2, '2014-01-03', 30,1), (2, '2014-01-05', 40,1), (2, '2014-01-05', 50,2), (3, '2014-01-06',…
-
2
votes1
answer2008
viewsSQL Server - Split Function
I have the following table: The goal is to make, in SQL Server, a function Split (by ',') the column EixoX where the TipoGrafico is different from 'Stockchart'. That is, if the TipoGrafico is…
-
2
votes1
answer212
viewsWhat is the difference between Integrated Security and Persist Security?
In connection strings with SQL Server I usually see the options Integrated Security and Persist Security, What each of them means and what values they can receive? This doubt arose me seeing the…
-
2
votes4
answers4389
viewsSelect from previous months
I need to do select data from previous months, month by month. My query is like this: SELECT * FROM VIEW_INCD WHERE MONTH(DH_CRIA_INCD) = DATEPART(mm,GETDATE()) - 1 AND YEAR(DH_CRIA_INCD) =…
-
2
votes0
answers354
viewsFilter the datagridview (Row filter)
I have an SQL database with two tables. One of them stores measures created(table 1) and other actions of these measures(table 2). I have entered on form one datagridView with the data of table 1…
-
2
votes3
answers529
viewsDifference between dates in months with decimal return
Good morning ! I am using the command below and the result returned is 6. In fact, looking at the dates, I haven’t exactly closed the 6 months, I think that through this function are not being…
-
2
votes2
answers395
viewsHow to extract the date-time of a given XML field in a string - Query SQL Server 2012
Good afternoon! Guys, in my log table there is a field called logdescricao and in this field it stores several expressions. For example: <log expressao="7085"><par traduzir="N">André…
-
2
votes1
answer507
viewsHow to create a View with filter?
I created the following query in my BD, I need to create a View from this query, the same should return the 3 initial columns realized, meta and accumulated, according to which the select is…
sql-serverasked 6 years, 3 months ago Gabriel Paixão Justino 287 -
2
votes1
answer135
viewsBank without PK, but I checked the PK by the Entity. Is this a problem?
I’m having trouble with fields float. Well, that post will deal with another matter, but I thought I could somehow infer in this problem. I stopped to think and analyze the subject. This is the…
-
2
votes2
answers136
viewsNull Result Coming in query
Good morning, I need a help from you, I have a query in my system is with a problem, it brings 4 results, only 1 of these 4 is coming with null value. I will post my query below SELECT Title,…