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
-
5
votes4
answers1917
viewsHome Time in SQL (Years, months and days)
I need to create a SQL function that returns the employee’s home time, example: years old, months and days So far I’ve managed to bring the years old and months, but I couldn’t get the logic of day…
-
5
votes2
answers168
viewsClause similar to Mysql LIMIT in MSSQL
I need to run the query below in PHP with SQL Server, however I cannot use the clause LIMIT absent in darlings microsoft. $SqlTabelaAtual="SELECT * FROM BusinessCadTabPreco RIGHT JOIN…
-
5
votes1
answer286
viewsSQL Injection with PHP + Sqlserver
How can I prevent SQL Injection from input via POST using PHP + Sqlserver. (Using Microsoft SQL Server => mmsql) I’m doing the data abstraction of a comic that runs MYSQLI and in this case is…
-
5
votes3
answers5377
viewsSELECT IN A RELATIONSHIP WITH SELF RELATIONSHIP(Verifying Conflicts)
I’m having trouble making an appointment. The situation is as follows, I need the bank to return all the names of the disciplines that have no prerequisites and that are not prerequisites. This is…
-
5
votes3
answers21403
viewsTurn rows into columns with their respective values
I have the following table idRegistro|Campo |Valor 1 |Nome |Zonaro 1 |Email |[email protected] 1 |campoX|valorX 2 |Nome |Fulano 2 |tel |1188889999 2 |campoY|valorY I need to create a select that…
-
5
votes3
answers2025
viewsHow to save a Base64 image to SQL and save it locally as PNG
I need to know if it is possible to save a Base64 image in SQL and then retrieve it and save it locally as PNG or JPEG. I already know how to convert to Base64, but to download in all browsers this…
-
5
votes2
answers380
viewsHow to transpose the result of a search using SQL Server?
Or better saying how to make the columns of a search result SQL Server, become lines of the result, as follows in the images below: A search result using the clause select whichever: Make the result…
-
5
votes1
answer1790
viewsImport Excel to Sql Server C#
I need to import a file excel for a table SQL. However, I need to pick up the lines and go between them because it won’t be all the information I will get from excel. I have exactly what I need but…
-
5
votes2
answers801
viewsKeep table records synchronized between two different databases
We are performing a system migration, where some restructurings will be done in the current bank in a new bank. Basically I will have two banks BancoVelho and BancoNovo, having to keep both of them…
asp.net-mvc asp.net sql-server entity-frameworkasked 8 years, 7 months ago Pablo Tondolo de Vargas 5,444 -
5
votes1
answer762
viewsHow does Sqlbulkcopy work?
I’m using in my class project SqlBulkCopy to mass input data. Everything has worked perfectly, but in recommending this to my co-workers, despite proving the efficiency, questioned about the…
-
5
votes1
answer1048
viewsCan I invoke Function on a Trigger?
My Function done on Sql-Server: CREATE FUNCTION dbo.getQuantidade(@idProd char) RETURNS float AS BEGIN DECLARE @QTD float SET @QTD = (SELECT (prod.Quantidade) FROM Produto prod where @id_prod =…
-
5
votes2
answers15372
viewsConversion of an nvarchar data type into a datetime data type resulted in a value outside the range
Code line INSERT [dbo].[Shop_Goods] ([TemplateID], [Name], [Remark], [CategoryID], [Description], [Attack], [Defence], [Agility], [Luck], [Level], [Quality], [Pic], [MaxCount], [NeedSex],…
-
5
votes2
answers5281
viewsBackup sql server express database using . bat
I created a file .bat with the content: USE T4FAT; GO BACKUP DATABASE T4FAT TO DISK = 'C:\Dropbox\MF-YCORN\BK_MF\T4FAT.Bak' WITH FORMAT, MEDIANAME = 'T4FATBackups', NAME = 'Full Backup of T4FAT'; GO…
-
5
votes3
answers421
viewsQuery with conditions in SQL SERVER
Follow the tables below with my question I have a problem, where I make a filter in which I need to get the posts that have the column post_parent of the post table with value other than 0, and also…
-
5
votes1
answer1258
viewscompare and add in sequence with sql server
through a table I intend to add the fields of col3 verifying if the value of col2 is equal to the following, doing a group by sequential. col1 col2 col3 ind seq1 5 ind seq1 3 ind seq1 7 ind seq1 4…
-
5
votes2
answers32603
viewsHow to get the size of each table in the database?
Through a query, how can I get the disk space that the tables (in a database) are occupying? I can list all tables using sys.tables, but, and the size? SELECT NAME AS NomeTabela FROM sys.tables…
-
5
votes1
answer977
viewsDoubt on how to print datagridview in reportviewer
I need to print the data of a Datagridviewer, which is the products launched in the sale. What is the best way to print this information in the Report? I tried to use the Table component, but I…
-
5
votes2
answers190
viewsSystem modularization
I’m developing a C# system with Winforms from Livestock Control to a farm, and will communicate with a scale to improve the weighing process. Some of the features are (Bill entry, vaccination,…
-
5
votes1
answer546
viewsDifference between Users and Logins
In SQL Server we have the option to create logins and database users. What’s the difference between the two?…
-
5
votes2
answers1969
viewsHow to get the Primary key Identity of an inserted record?
I need to create a stored procedure to insert a game into my database. A game relates to a championship through the table campeonatoJogo. The tables are basically: create table jogo( codJogo int…
-
5
votes6
answers32941
viewsConvert varchar to date in SQL
You can convert dates into sweep for date. I’m having difficulties in performing searches between dates, due to this discrepancy in the database where I perform the query. When I enter my line of…
-
5
votes3
answers1988
viewsHow many days to a date
Does anyone have a query in sql server that returns how many days to a date? I have the employee’s admission date, I need to know, how many days are left to complete 45 days and how many days to…
-
5
votes1
answer663
viewsHow to export data from R directly to sql server?
Friends, I consumed a web service with R and now I need to export this data directly to sql server. How do I?
-
5
votes1
answer72
viewsHow to kill, remove or not initialize the SQL Server master database?
I woke up in the morning and gave a "Run" on top of the bank "cotacao", bank that I am working at the moment. Then came the login screen and when I logei the bank that received the tables was the…
sql-serverasked 6 years, 12 months ago pnet 14,727 -
5
votes1
answer1341
viewsHow can I list all invalid emails?
I ended up finding something like this due to the lack of validation that we didn’t have. teste@cliente calteste5@calteste5 calteste6@calteste6 vava@ius Pablo Fernandes xxx eduardostubbert 123456…
-
5
votes2
answers402
viewsHow to select records in an Auto-referenced table using Recursiveness?
In a scenario of areas where one area can be supervised by another is representing in a tree structure as follows: Problem: The need to select the Área (CBT - Cubatão Industrial Complex) plus all…
-
5
votes1
answer1044
viewsHow to bring only a certain part of a text in a field
How do I bring only a piece of text into a field in sql server? I have the query below that in the Description column, it returns a text with a lot of information as for example. Nome Cliente Data…
-
5
votes2
answers172
viewsSQL SERVER - Convert String in Days
How can I convert this string in days? Example: return "2 days and 2 hrs"? SELECT '50:00:00'
-
5
votes3
answers4418
viewsError in a simple SELECT with Group By - SQL Server
I’m trying to do the following SELECT: SELECT P.Nome,P.TipoId,P.QuantidadeMensal FROM StockPhotos.Pacote P GROUP BY P.QuantidadeMensal; But I’m getting this error message: Message 8120, Level 16,…
-
5
votes1
answer782
viewsHow to create Trigger for all tables in a bank automatically?
Example scenario I have a database with 1,000 tables. One table call log. Goal I would like to create a Trigger "standard" in each of these tables, automatically. That one Trigger, whenever there is…
-
5
votes1
answer228
viewsA Rigger can "undo/undo" the action that triggers it?
Example scenario I have a table telefones where I have a Trigger that is fired while performing the instruction Insert. Doubt I can use the Trigger for verify a condition and before the return,…
-
5
votes3
answers1003
viewsHow to make a select within a condition?
How can I create a script in SQL where a SELECT, and as the result of a column of this first, performs a certain condition of another table? example: select * from tabela as t SE t.saldo = 0 entao…
-
5
votes2
answers67
viewsDifference in performance when Duplicate a table
There is significant difference in performance between these two examples? SELECT * INTO [IP].BA_exemplo.dbo.TabelaB FROM BA_Temp..TabelaA and SELECT A,B,C,D... -- (todos os campos da tabela…
-
5
votes1
answer531
viewsPivot T-SQL Dynamic Sequential
Breaking my head here to create a proc using pivot for this transformation: There is the possibility? *Using sql server 2008R2 EDIT: CREATE TABLE #Teste5 (name VARCHAR(50),message…
-
5
votes1
answer157
viewsError converting varchar to integer
By performing the following UPDATE through my API (.NET Core): UPDATE Aula SET WHATEVER = WHATEVER WHERE ID_AULA = @examID Code: string query = builder .AppendLine("UPDATE Aula") .AppendLine("SET…
-
5
votes1
answer106
viewsOnly positive numbers in SUM aggregation
In this consultation, in ,SUM(quota_re_mes1) AS NO_MES i would like it to add up only the positive numbers, is there any way to do that? SELECT orcdotac.conta_desp ,orcplade.descricao…
sql-serverasked 6 years, 5 months ago V.Avancini 496 -
5
votes1
answer537
viewssqlsrv_num_rows does not work
I have a site that is being done with PHP + SQL SERVER, and to log in needs client code, and it puts there only that always says that is incorrect, and that is correct. Apparently the…
-
5
votes2
answers121
viewsPlace row data in columns
SELECT datacc, horacc FROM R070ACC WITH (NOLOCK) WHERE numcad = '2676' AND DATACC between ('2018-16-04') and ('2018-15-05') and oriacc = 'E' In the first column appears the day of the month repeated…
-
5
votes3
answers147
viewsJoin between banks
Staff I am running the command below but I haven’t gotten the desired result. USE banco1 SELECT * FROM sistema.tb_menus_perfil_params a LEFT JOIN banco2.sistema.tb_menus_perfil_params b ON a.pm_id =…
-
5
votes1
answer695
viewsSELECT within variable in PROCEDURE
I’m not getting the result of a select within a variable. I want to add the column turno inside my WHERE. The problem is I get the value of @turnos in the following 3 formats: 1 - 'A' 2 - 'A','B' 3…
-
5
votes1
answer67
viewsIs it possible not to allow duplicity in a combination of 2 columns or more?
I know that SQL Server has the Primary Keys and start not to allow duplicate records, but it is possible to do this through 2 columns or more? As an example, I have a table with column, house and…
-
4
votes3
answers882
viewsHow to insert an extended value into a table in a varbinary column?
A table has a varbinary(max) column, I need it to have a 400MB input of data in this column. How I create this data? The Insert statement has to have the data in full or I can use a loop or a…
-
4
votes2
answers2443
viewsT-SQL with case sensitive like
Is it possible to make a query in SQL Server 2008 with sensitive like? Actually, I’m looking in a column with a list of acronyms, which represent system flags, which differentiate uppercase and…
-
4
votes2
answers747
viewsEF6 Code First Relation between entities
I am trying to create a Condominium data model in ASP.NET with SQL Server. I stumbled on the creation of the interface proprietario(1) with the fracao(many). The error returned is: The INSERT…
-
4
votes1
answer8024
viewsHow to determine permission to use tables?
How can I make a certain user "see" one table and another not? I’ve been doing some research, I found the DENY SELECT ON *** but I was unsuccessful.
-
4
votes2
answers2986
viewsSelect a table that simulates a tree
I have a table that simulates a tree. For example: DECLARE @t TABLE(id int,parentId int,name varchar(max)); insert @t select 1, 0 ,'Category1' insert @t select 2, 0, 'Category2' insert @t select 3,…
sql-serverasked 10 years, 6 months ago amws 63 -
4
votes4
answers2880
viewsIs it possible to reference a column that is not a primary key in another table?
For example, I want to reference the id_2 of Table 1 in Table 2, I know I can do with primary keys but with other columns I do not know if it is possible. Table 1: id (primary key of Table 1), id_2,…
-
4
votes1
answer543
viewsConnection provider not working in Vbscript
I have the following connection string: conn = "Provider=SQLNCLI; Server=" & conn_server &"; Database="& conn_database &"; UID="& conn_uid &"; PWD="& conn_pwd And the…
-
4
votes2
answers1970
viewsUse PIVOT operator without aggregation
I have the FAULTS table with the following columns: CREATE TABLE [dbo].[FALTAS]( [Id] [int] IDENTITY(1,1) NOT NULL, [Matricula] [int] NOT NULL, [Dia] [date] NOT NULL, [Situacao] [varchar](50) NOT…
-
4
votes2
answers1073
viewsConcatenate table name loop sql server
I’m trying to fill a table of mine with a loop in sql server follows the code: declare @i int set @i =1 while @i < 5 begin INSERT INTO TABELA VALUES('teste') set @i = @i + 1 end I would like to…