Stack Exchange Network

Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange
The results are in! See what nearly 90,000 developers picked as their most loved, dreaded, and desired coding languages and more in the 2019 Developer Survey.

Questions tagged [sql-server]

All versions of Microsoft SQL Server (not MySQL). Please also add a version-specific tag like sql-server-2016 if that is relevant to the question.

2
votes
2answers
30 views

Filter Table by a Historical 'Last Day of the Month'

I have a daily appending table, that I need a formula for that would filter the table results to just the last day of any given historical month. For example: Table: DwDate Balance ...
0
votes
0answers
21 views

bcp: dsn specified an unsupported driver

A straight-forward call to bcp works on linux and not on windows. Ubuntu ~$ /opt/mssql-tools/bin/bcp "select @@version as v" queryout foo.csv \ -D -S mydsn -c -U myuser -t, -r '\n' -P '...' ...
0
votes
0answers
19 views

SSISDB Start and Stop time for each Package

I am trying to query the SSISDB Project Catalog to review the Start and Stop time for each SSIS package. Is there any native query to conduct this? I am checking [internal].[executions], SSISDB....
-3
votes
1answer
22 views

Using a calculated column in a SQL Select statement

I am trying to write a query. Column A comes from database, column B is either 1 or -1 and it is result of a CASE statement that looks into the same table. Now, my column C needs to refer to column B ...
0
votes
1answer
19 views

How to monitor a file share witness for accessibility

In the context of a SQL Server Availability Group, what's the best way to monitor a file share witness for accessibility? I want to make sure the witness can be accessed by the Availability Group ...
2
votes
1answer
27 views

Microsoft Sql Server - How to replicate a table from Linked Server?

I have an Origin Database - #1 with very restrictive access due to security. I provisioned a new Windows desktop machine with Microsoft Sql Server Management where I created a local database with all ...
7
votes
2answers
2k views

Why is my log file so massive? 22gb. I am running log backups

I can't seem to figure out the answer. I've seen multiple answers like this: Why Does the Transaction Log Keep Growing or Run Out of Space? and everyone talks about running back ups on your log file ...
2
votes
2answers
57 views

GROUP BY a number of DAY in SQL Server

I have this query SELECT dbo.f_DateWithoutHour (0,DATEADD (DAY, 3, TheDate)) AS Date FROM ( SELECT TheDate FROM xxxxxxx.dbo.dim_date (NOLOCK) WHERE TheDate >= '...
-1
votes
1answer
64 views

Retrieve records when value in column changes [closed]

I am using SQL Server 2012. I have this table below. I would like to get records when the Name changes (see column result). I' m not getting with this code. SELECT [Date], [Name] FROM myTable as T1 ...
4
votes
1answer
514 views

Check if two datetimes are between two others

Today I'm facing with problem, which I can't solve. I need to check if two datetimes (2019-04-08 13:30:00 - 2019-04-08 15:30:00 ) are between or overlap two others (2019-04-08 14:00:00 - 2019-04-08 ...
0
votes
1answer
25 views

Using Resource Governor to limit query CPU usage for same user

I have a remote MS SQL Server and I have several types of queries. I run some queries that are part of a low-latency production application, and need to ensure they get domne in a timely manner. But ...
0
votes
1answer
58 views

Database Blocking, kill the session which is responsible after 5 minutes

I have been struggling with database blocking at my database server from last so many months. Have tried to use many ways to capture them and also aware that who are leaders of blocking. This ...
0
votes
0answers
26 views

Configure Availability Group in SQL Server 2016

Can you tell me how you add the second node as the replica to the AG? I am using this feature on AWS instances, I have followed all the steps as shown in different videos, but when I try to add the ...
0
votes
1answer
14 views

having 'Measure' > 0 syntax does not work in mdx query

Hope you're doing well I've written an MDX query as you can see below : with member [Measures].[TOTAL] AS SUM(Periodstodate([DimTime].[Year].[(All)] ,[DimTime].[Year].currentmember) ,[Measures].[...
1
vote
2answers
65 views

What is the best practice when an index with key/include columns are inversed for a second index on the same table

I have an index on a table of the form: NONCLUSTERED INDEX [IDX1] ON [TABLE] ( [COL_ID_A] ASC ) INCLUDE ( [COL_ID_B] ) For a different query on the same table MSSMS proposes the following ...
1
vote
2answers
53 views

Resetting a new archiving database

I have an archiving question. We have a History DB used for archiving old records from our main system and the application knows to query it However, it becomes too big. I would like to ...
0
votes
1answer
32 views

Added New Subscriber but Replication Not working

I have one Merge Replication setup with one Publisher and 5 to 6 Subscribers. We have added one additional subscriber to this replication and when we try to sync it's giving the following error. ...
8
votes
2answers
667 views

how to create a data type and make it available in all Databases?

If I create a stored procedure in the master database, and I want to execute it from any of my databases I just follow this link: Making a Procedure Available in all Databases that give me this code ...
2
votes
2answers
61 views

Why does CONTAINS not find matches at the end of the string?

I have a stored procedure in Microsoft SQL Server 2008 R2 (SP3) which searches a table for anything matching a @Keywords parameter that I pass in. It was too slow using LIKE as the table has 155,000 ...
0
votes
1answer
20 views

Load flat file into a predetermined table

Scenario Table created Data in flat file loaded to the table but with errors. please advise how to fix it (a) 'address' is split to 3 columns causing mismatch between the source and destination (b)...
0
votes
0answers
17 views

SQL server 2014 new publication error “A generic failure occurred during Service Master Key encryption or decryption.”

I'm trying to create a new local publication (replication , Transactional Publcation) on my production data base but i'm getting an error A generic failure occurred during Service Master Key ...
1
vote
0answers
25 views

SSMS - Data load Option

I have recently installed the newer version of SSMS on my system. But the option to load the excel file is grey out. I'm not able to load BULK Load I tried to run DTSWizard.exe, even it doesn't give ...
2
votes
1answer
93 views

Direct values on predicate produce not-so-good plan

I'm using StackOverflow dump to run some tests. In particular, I'm querying this table: I have created this index: I'm running the following query (just forcing an index to test alternatives) I ...
10
votes
5answers
3k views

The use of multiple foreign keys on same column in SQL Server

SQL Server allows me to create multiple foreign keys on a column, and each time using just different name I can create another key referencing to the same object. Basically all the keys are defining ...
0
votes
1answer
61 views

Cannot open database “dbname” requested by login.The login failed.Login failed for user 'DOMAIN\Windowsusername'

I had a database which i dropped using the below command. USE master; GO ALTER DATABASE dbname SET SINGLE_USER WITH ROLLBACK IMMEDIATE; GO DROP DATABASE dbname; Now when i refresh the connection in ...
0
votes
0answers
13 views

SQL Server 2017 two different Netbios names

Situation: Migrating SQL Server database from 2003 to SQL Server 2017 moving to new hardware. SQL Server 2003 is on a machine with a netbios name of "Albert" on port X.X.1.22 Installed new SQL ...
0
votes
1answer
18 views

DBCC INPUTBUFFER shows Event Type as Language Event for an unused Database

In my production SQL Server 2016 server,i had few dummy databases created as part of migrating from SQL Server 2008. I was cleaning up all the unwanted databases and i dropped few databases.But when i ...
1
vote
3answers
49 views

Maintaining data integrity when one table has multiple relationships, but only one should be used. (is this bad design?)

I'm working on a database that holds laboratory medical testing orders. The issue I have (maybe) is that I have a table that holds an order number, and a test code. There is also a TestNumber PK. ...
2
votes
1answer
84 views

Run SQL Agent Job 3 times in a Row

How do I execute SQL Agent job 3 times in a row? We are creating Data Warehouse Project. It ETLs data from Flatfile Legacy Folder, and creates Dim and Fact tables. SSIS Project Environment Variable (...
5
votes
2answers
156 views

dbcc cleantable batch size explanation

I have a very large table with 500 mil rows and a Text column that I will be dropping. In my Dev environment, I have dropped the column and began the reclaim process, but im not sure what the batch ...
0
votes
0answers
32 views

Changing DB mode from restricted user to multiple user is taking time in taking effect

In my installer, I need to set the setup Maintenance Mode and when done, I have to reset the same. As implementation, I set the DB mode to restricted user mode. executed all my required queries in ...
3
votes
1answer
60 views

ms sql query multiple table colums as identical tag (sequel)

Extending this original question I am using SQL Server Express 2017 Pretending this is my source table: +-------------+---------------------------+ | ID | Name | Age | HairColor | HasCar | +-----...
0
votes
1answer
11 views

Access control on Azure SQL Data warehouse

Access Control setup on Tables inside dbo schema. We are Denying select permission on some tables inside dbo schema as these tables have some critical data. Issue: Even when Select query fails on ...
0
votes
2answers
56 views

Attempting to backup to remote NAS but access is denied

I was attempting to use Ola Hallengren's scripts to backup to a remote NAS, but it was failing and not giving any direct errors, so I tried doing it manually using Server Management Studio and got the ...
2
votes
1answer
50 views

Make database writeable (Azure MS Sql)

I have a bacpac file from a read-only database hosted on Azure. When imported to a new server the database is also read-only. I’ve tried looking for answers with no luck. How can I change it to a ...
0
votes
1answer
57 views

Query taking more time to execute due to lengthy column size

When I am trying to execute below query in SSMS, the query is taking more time (more than 10 minutes) to execute due to lengthy column size (Column Name: Keywords, Column Size: nvarchar(4000)). ...
1
vote
1answer
26 views

Server Principal SID showing as NULL and name as empty string

In my SQL Server 2016 server,i set up a user logins Audit for Login successful and Login Failed action. Here is the script. USE [master] GO CREATE SERVER AUDIT SPECIFICATION [...
0
votes
0answers
24 views

Indexing strategy for date range availability in SQL [duplicate]

Imagine the structure of a simple hotel booking app: hotel_chain(id, name) hotel(id, hotel_chain_id, name) room(id, hotel_id) booking(room_id, date_start, date_end) There are hotels, that belong to ...
-1
votes
0answers
34 views

Admission count in SQL

In above scenario, Patient A has been admitted to ER to Hospital A and then transferred to another ER hospital or they may transfer to Hospital in a day or on same day. I need to calculate the ...
0
votes
2answers
43 views

ms sql query multiple table colums as identical tag

I am using SQL Server Express 2017 My Table looks like this +-------------+ | ID | Name | +-------------+ | 1 | Bert | | 2 | Agnes | | 3 | Diane | +-------------+ I'm looking for this kind ...
-2
votes
0answers
49 views

SQL Server does not recognize created objects [duplicate]

When I create a table on my server create table DocumentType(id int, .......) SQL Server created it, I can insert rows in it and query it, but when I hover on object names it says 'Invalid object ...
5
votes
1answer
165 views

How do I find out when a node was added to an availability group?

Ideally, I am looking for T-SQL that returns two columns: the node name, and the date/time that node was added to the availability group, for all nodes in a given availability group.
2
votes
1answer
26 views

Recommended Permissions for SQL Account that will be creating new SQL Accounts

Seeking some recommendations on how to handle a SQL account, that will be creating additional SQL accounts in the future... Scenario: Our Admin production app connects to SQL using an account called:...
-1
votes
1answer
44 views

Replace NULLs with value

Here is my temporary table: CREATE TABLE #test123( c1 float, c2 float, c3 float, c4 float, c5 float ); INSERT #test123(c1,c2,c3,c4,c5) VALUES (2,3,NULL,1,2), (2,NULL,NULL,...
5
votes
1answer
148 views

What is DBCC SHRINKFILE actually doing?

I have a database which was 11TB in size. I recently truncated over 5TB of data from this database. (I am fully familiar with all the reasons why you would not normally shrink a database please) I'm ...
0
votes
0answers
62 views

Regarding NIGHT SHIFT Employees

I have small issue on night shift of our employees. Shift timings are from 22:00 to 6:00. If the shift starts today at 11 PM it will end the next morning at 6:00 AM (7 Hours ). Here I want to know ...
3
votes
1answer
40 views

Tracking grant violations

We are changing one of our application user logins from being dbowner to a more granular permission scheme--finally. Is there a way from within SQL Server 2016 that I can track permission violations? ...
4
votes
3answers
187 views

Cursor Replacement for Newbies

I'd like to know what the general replacement is for a cursor. The general implementation of a cursor I see out and about is DECLARE @variable INT, @sqlstr NVARCHAR(MAX) DECLARE cursor_name CURSOR ...
1
vote
0answers
24 views

AWS RDS Performance Insights not showing SQL Server Queries

I enabled Performance Insights on an existing SQL Server database (Express, if it matters) in AWS RDS. If I look at the database load graph and table I do not see any of the queries I am doing in real ...
0
votes
0answers
34 views

Query plan cache seems to be being cleared after every query

I am attempting to get some data on slow queries using via making queries to different DMVs. However I keep receiving an empty table of results. The root problem seems to be that the query plan cache ...