Questions tagged [sql-server]

Microsoft SQL Server is a relational database management system (RDBMS). Use this tag for all Microsoft SQL Server editions including Compact, Express, Azure, Fast-track, APS (formerly PDW) and Azure SQL DW. Do not use this tag for other types of DBMS (MySQL, PostgreSQL, Oracle, etc.). Do not use this tag for issues on software and mobile development, unless it is directly related to the database.

sql-server
Filter by
Sorted by
Tagged with
-1 votes
2 answers
531 views

Convert a WPF application w/ database into a real service

I developed a WPF application using SQL Server Management Studio 2014 with Entity Framework. During all this time on this area, I've never get how to convert an application into a real service. If ....
Joseph Doe's user avatar
-1 votes
2 answers
48 views

SQL Server, combine tables with filling null values

I have three tables: Customer, Sales, Detail Customer table columns: CustomerID, CustomerName Sales table columns: Date, Invoice, CustomerID Detail table columns: Invoice, ItemID, Quantity Customer ...
user avatar
2 votes
1 answer
702 views

Inserting new XML attribute using .modify() - how to make it last attribute?

I am trying to update the data in an XML column, and add a new attribute if it doesn't already exist. Here is the most relevant portion of my script: UPDATE sp set [PolicyXML].modify ('insert ...
Allen's user avatar
  • 927
3 votes
0 answers
2k views

Issue with SQL Server Query store

Few weeks back I did run an in-place upgrade from SQL Server 2016 to SQL Server 2017 CU 5 in one of our main environments. I used Slipstream upgrade so it was one shot. This is a 2 nodes shared ...
Javier Villegas's user avatar
0 votes
1 answer
27 views

How to compare the latest two values for a given set of data

I need a query that will give me the latest Author, Publisher, and Book for each author that published a book on the MAX(PublishDate) and compare the publisher from the latest 2 books per Author to ...
edeevans's user avatar
1 vote
2 answers
6k views

SQL Server: Why is the backup speed so slow?

I have a backup query like this: BACKUP DATABASE @temp_baza TO DISK = @temp_bak BACKUP LOG @temp_baza TO DISK = @temp_log It is run by sqlcmd like this: sqlcmd -l 120 -S %SQL_SERVER% -i %...
Michał Lipok's user avatar
1 vote
1 answer
5k views

How to do a SQL-type INNER JOIN in Python and only naming a couple of column names? [duplicate]

I am experienced with SQL, but am new to Python. I am attempting to use the join or pandas.merge functions to complete the following simple SQL Join: SELECT a.Patient_ID, a.Physician, b.Hospital ...
Samsonite Manly's user avatar
0 votes
1 answer
285 views

SQL: Find first occurrence of any character except the one specified

All, Using SSMS v17.2 Long story short I have 15 columns in a table, each record in the table has a different number of columns filled out, the rest are null. I then concatenate the columns with a ...
J.Pyz's user avatar
  • 213
1 vote
3 answers
51 views

Rearrange a text into a different order using SQL

I have a text RAW/+A/@B/abs.m>C and it has to be converted to A.B.C Could someone help me with an efficient SQL. I am struggling to build one. This is the rule to be followed - use whatever is to ...
Dilip's user avatar
  • 153
1 vote
3 answers
307 views

Is CROSS APPLY the correct method to join a table with no unique identifier for all rows (duplicate records)?

I am pretty new to SQL. I am trying to join two tables, tblEmployeeHours and tblWages. However, the Wages table can contain duplicate rows. Here is a snippet of the EmployeeHours table: x------------...
eggman's user avatar
  • 13
0 votes
2 answers
860 views

How to generate Reshift compatible table schema from a SQL Server table

I'm trying to create an automated pipeline to transfer data from a SQL Server table to my Redshift database. I need to do this for several tables, currently in SQL Server. The process I'm doing for ...
Anjali's user avatar
  • 23
-2 votes
2 answers
209 views

SQL Server : how to split a string into multiple rows?

Can you help me with this situation? I have this string in a DESCRIPTION column (yes, that's the only column with the data for this case =/ ): "P.A. - Solicitação [945159][945171][944007][944836][...
Jonathan Alves's user avatar
5 votes
2 answers
145 views

SELECT query to get child elements from xml datatype

I have the following SQL script (and the XML structure at the bottom): DECLARE @questions XML SELECT t.Col.value('QuestionId[1]', 'int') AS QuestionId, t.Col.value('Options[1]/string[1]', '...
SRAMPI's user avatar
  • 373
3 votes
0 answers
44 views

Evaluate dynamic column name inside update function in a T-SQL trigger [duplicate]

I'm trying to determine if it's possible to use a dynamic column name inside an Update Function in a T-SQL trigger. In my table I have a column, "Last_Name". Inside the trigger I'm able to evaluate ...
Rohil's user avatar
  • 45
0 votes
2 answers
10k views

How to get table definition of a table in SQL Server

I'm new to SQL Server. There are a couple of tables that in my team's database that we need to replicate. I was wondering if it's possible to get the DDL of the tables. Like for a specific table, get ...
Anjali's user avatar
  • 23
1 vote
1 answer
135 views

Retrieving identity column after inserting data using SQLBulkCopy

I have a model: public class A { public int NameID {get; set; } //this represents the identity column in the database public string Name { get; set; } public string Value { get; ...
Denis's user avatar
  • 12k
0 votes
1 answer
147 views

SQL Server CROSS APPLY

I'm trying to add in a CROSS APPLY to this query. I've never done one before, but a co-worker suggested it and it seems to make sense. I'm getting a syntax error though. Here's the query: ...
Matt Larsuma's user avatar
  • 1,476
-1 votes
1 answer
579 views

How to copy a record from Excel and paste into SSMS V 17 to update existing record

Folks, I am a novice, really a business user (not techie), in SSMS v 17. I used to update a MS Sql Server database in Azure using Excel add-in (Devart), but then Active Directory Multifactor ...
Kan Yan's user avatar
-2 votes
1 answer
1k views

bit data type in JSON

I have a table that stored 'bit' type values. In my SQL procedure I call that field to make my output of XML format and I convert that output to JSON online. Doing so, my JSON output does not obey '...
Rick's user avatar
  • 1,474
-1 votes
4 answers
37 views

Select the Max date time for single User

I have a table like this, Date User 15-06-2018 A 16-06-2018 A 15-06-2018 B 14-06-2018 C 16-06-2018 C I want to get the output like this, Date User 16-06-2018 A 15-06-2018 B 16-06-2018 ...
Srinivasan Rajasekaran's user avatar
1 vote
0 answers
87 views

Cross joining tables to see which partners in one table have a report from another table [duplicate]

New to SX and Just beginning my delve into the world of programming and could use some assistance with this problem. I need to find out which GROUP of partners from the MentorRelations table don’t ...
Michael B.'s user avatar
0 votes
1 answer
374 views

SQL XML .Modify syntax

I'm trying to figure out what wrong with my XML update query. I don't have much experience working with XML in SQL but I thought this should work. I want to update a value of the PATH value in XML. ...
Hannover Fist's user avatar
0 votes
1 answer
584 views

SQL Server : Sum function is returning wrong value

So this is my query select a.ERSDataValues_ERSCommodity_ID,c.ersGeographyDimension_country, b.ERSTimeDimension_Year, sum(a.ERSDataValues_AttributeValue) as Total from cosd.ERSDataValues a ,...
Bharat Radhakrishnan's user avatar
1 vote
1 answer
51 views

How to debug an issue in a proprietary SQL database

Our application from a vendor is using SQL Server 2008 R2 as its database on the backend. Although rarely, but sometimes an issue comes up that we think is related to their database (for example a ...
nam's user avatar
  • 23k
1 vote
2 answers
39 views

Conditional field replacement in tsql

I am trying to take some data like: Col1 | Col2 | Col3 | Col4 ------------------------- One | Two | NULL | Foo Two | Bar | Baz | NULL And I want to recognize if there's a null or not. Like, as ...
Jon Finstad's user avatar
0 votes
1 answer
35 views

Is it possible to load this xml with sqlxmlbulkload?

Is it possible to load a similar xml into these tables with sqlxmlbulkload? xml: <?xml version="1.0" encoding="utf-8"?> <a> <b> <code>1</code> <ds1>1....
Peter Janvarev's user avatar
1 vote
1 answer
3k views

Entity Framework 6 Code First on SQL Server: Map "bool" to "numeric(1,0)" instead of "bit"

Forward warning #0: upgrading to EF core is not an option in the near future. Forward warning #1: I can't change the column type to bit because this could potentially break legacy VB apps that employ ...
XDS's user avatar
  • 3,972
2 votes
1 answer
4k views

SQL Server: cannot create a linked server, says it already exists

I need to create a SQL View to query data on another SQL Server. This link explains how to do it: http://www.mytecbits.com/microsoft/sql-server/joining-tables-different-servers However I cannot work ...
arame3333's user avatar
  • 10k
-2 votes
3 answers
3k views

Get Previous Friday in SQL

How to get previous friday in SQL Server? Here is the code I have so far: select (7 -datePart(dw, getdate()+3)) +1
Bharath T's user avatar
2 votes
0 answers
1k views

Increasing Database Size, how much and when?

I have worked in SQL Server for the past ~10 years, always on the development side, but I find myself in the DBA position. I am looking at our main database, small 90GB, 30GB for the log and only 6GB(~...
Holmes IV's user avatar
  • 1,701
1 vote
2 answers
77 views

MsSql get a blank record based on structure

is there a way to receive back from SHOW COLUMNS FROM xxtable a blank record with the fields from the table? Currently, I can get a record return if my search criteria is met - when doing: SELECT * ...
user3861284's user avatar
0 votes
1 answer
26 views

Convert column Ageday to blank value instead of zero

.DischargeDate) ELSE '' END AS 'AgeDay' Please help me that in ageday column I should be able to see empty string rather than null or o but now I'm seeing 0
Santhosh kumar's user avatar
0 votes
2 answers
736 views

Extract words from comma-separated string to individual rows

I have the following table: (RowNumber int, Names (varchar(50)) I need an update statement or function that separates all words between commas into different columns as: I have tried the following ...
l217's user avatar
  • 93
0 votes
1 answer
788 views

How do you interpret a SQL deadlock trace?

We've got deadlocks occurring on our SQL server. I've read many pages on Stack Overflow and elsewhere, but I can't find a step by step instruction list for how to read the trace log. Can someone ...
boilers222's user avatar
  • 1,939
0 votes
2 answers
943 views

SSRS report Tables and Sub Reports

I have an SSRS, which has Games. Within each game, there are multiple teams, and then they are classified as offensive teams and defensive teams. So there is a game, then there is game detail. Within ...
missscripty's user avatar
0 votes
0 answers
59 views

Stored procedure suddenly hung - have the parameters sniffed?

I have a SQL Server 2016 stored procedure performing aggregated weighted average on over 300 columns. The procedure takes in begin_month, end_month, monthly_flag as input parameters. The logic with ...
Lucky's user avatar
  • 363
0 votes
1 answer
742 views

SQL Server (getutcdate()) inserts default value on external POST

I recently started diving into SQL Server Management Studio along with Web API 2. I followed a tutorial that instructed that I can get a current date for when a database row is inserted into the table....
CAlex's user avatar
  • 1,140
0 votes
2 answers
3k views

SQL Server on Azure: "Execution Timeout Expired. The timeout period elapsed prior to completion of the operation or the server is not responding."

I'm running a script locally in Powershell that loops bcp, copying hundreds of excel files to a database on Azure (I simply entered the network information as arguments to bcp). On each execution of ...
SuperNova's user avatar
  • 111
0 votes
1 answer
32 views

SQL Fetch the record closest to integer in another table

I have 2 tables. I'm tying to get the record(person) that has the most wins first. If 2 people have the same amount of wins then I need the person that is closest to the Total Points. In this scenario ...
Mike Nacci's user avatar
  • 4,319
1 vote
3 answers
273 views

Using patindex in SQL Server to check six continuous numeric values

I need to check if a string has 6 continuous numeric values in a string with the PATINDEX function. Examples (in parenthesis appears the number if it fits 6 digits): case 1 - s24334fth06 case 2 - ...
graphene's user avatar
  • 157
0 votes
0 answers
55 views

SQL Server : cumulative data for 10 days

Existing query: DECLARE @symbol1 VARCHAR(50) = 'D', @symbol2 VARCHAR(50) = 'N', @barDurationSeconds INT = 60, @daysOfData INT = 1 // it gets me one day and I want it for 10 ...
user1254053's user avatar
5 votes
1 answer
3k views

C# + DockerCompose - Wait for MS SQL Server Docker container to be up before trying to connect

I am trying to create integration tests for my microservices similar to Spotify's approach. I am still working on how to spin up and seed the database. Currently I have a .NET Core 2.0 project with ...
peflorencio's user avatar
  • 2,312
2 votes
1 answer
63 views

SQL Plan variance scientific notation

I'm dealing with a three piece datapath: client application, host integration server, db server. Client application (MS Mashup Engine) is generating queries that pass through MS SQL Server to a ...
Alexander Toptygin's user avatar
0 votes
0 answers
98 views

Transferring MDF/LDF files to target server

Background: I have a medium-sized database (900GB) that needs to be copied onto another server (driven via code, not scheduled). Currently we take a backup (to .bak), move it to a staging server, and ...
N. Squealer's user avatar
1 vote
2 answers
78 views

Get the first joined result based on business logic

My table T1 looks like this: ID VALUE ---------- 1 1 2 32 3 6 4 42 5 8 6 62 7 43 8 34 My second T2 looks like this: ID DEFINITION --------------- 1 A|B|C 2 er|All|All|B ...
gnopfelbrie's user avatar
1 vote
2 answers
58 views

How to set varchar to real date?

I have a field named 'Date' (believe it or not) and it is Varchar(50). Sigh. Anyway, I want to convert this to an actual date in another field in the same table. I tried a few things.. UPDATE ...
ASH's user avatar
  • 19.8k
0 votes
0 answers
67 views

Subquery returned more than 1 value. Not permitted when subquery follows =, but no subquery being used?

SELECT TOP 100 * FROM [Analytics].[KE30].[View_NewKE30] WHERE [ReportDate] = '2018-05-31' This returns the error: Subquery returned more than 1 value. This is not permitted when the subquery ...
JSrinivas's user avatar
0 votes
1 answer
536 views

format function in SQL

EDIT ON 18 June I am using SQL Server 2012. I use an administrative tool to connect to a database. For example, columns needed are id, year and month. I select the columns: Document_Header....
Sabiha Boudour's user avatar
0 votes
2 answers
220 views

Delete All Data Found With Query [duplicate]

I am working on a database project, and for sanity's sake I want to delete all of my problem data from the database while I test it's other features. I currently have some queries written up to help ...
Skitzafreak's user avatar
  • 1,857
0 votes
3 answers
1k views

MS SQL backup and restore with some condition

We have two virtual machines that one of them is live version of the system and one of them is the development environment. The problem is, when developers want to back up and restore the database ...
Mehmet Taha Meral's user avatar