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.

learn more… | top users | synonyms (2)

1
vote
0answers
7 views

UNION ALL or other ways to return first row of result-set

I am writing a table valued function to geocode an address based on its Suburb, State and Postcode. I try to geocode the address using different methods, in order of decreasing accuracy: Exact match ...
2
votes
0answers
15 views

File size when extracting from SQL Server to CSV

I am attempting to extract a table to CSV using BCP from SQL Server 2014 and the size of the file once the data is extracted is actually larger than the size of the database itself. One thing to note ...
0
votes
1answer
18 views

I need help to create query to distinct emails that not logged in to ABC please see details

I need help to write query to distinct emails that have not logged into ABC database in the past 5 months. the exact task I have been asked as following: "Create a table in ABC database with columns ...
1
vote
0answers
7 views

How to restore SQL Server database from Azure Blob?

I created a database (IaaS) from Azure marketplace (Windows server 2012 + SQL Server Web 2014). I Selected automatic backups to blob storage. Now I'm trying to do a test restore operation. I imported ...
3
votes
1answer
36 views

Transposing hierachical data from one VARCHAR to two INTs

THE PROBLEM The table where the data is recorded is CREATE TABLE [dbo].[Almoxarifado]( [idAlmoxarifado] [varchar](20) NOT NULL, [tipoAlmoxarifadoId] [varchar](30) NOT NULL, [entidadeId] ...
1
vote
0answers
12 views

Expose SSRS Reports in websites

I'm fairly new to the SQL Server stack, and am trying to wrap my head around how to best expose on-premise SSRS reports in websites (LAMP stack). URL Access appears to be what I'm after, as it lets ...
0
votes
0answers
25 views

Foreign keys not trusted but they were not disabled

Is there any other way that a foreign key would be marked as "is_not_trusted" besides disabling them and re enabling them incorrectly? They were created without the NOCHECK option initially (meaning ...
0
votes
2answers
24 views

Update field in SQL Server Table Dynamicaly

I need to do a 1 time update of a Sql Server table. The table has a unique ID, contains a member number field and a FileName field which tells us what file the member data came from. What I am ...
3
votes
1answer
130 views

Concatenation, with separators, where any combo of input fields might be null

I have three columns, CITY, STATE, COUNTRY. One, two, or all columns may be NULL. With the following logic, a single string is made using the SQL below. It is messy, and I am wondering if there is a ...
0
votes
1answer
39 views

Locking in Stored Procedures [on hold]

If a stored procedure has multiple statements,will the lock acquired for the first statement be released once its executed or will it hold on till entire SP is complete? I am running an SP under ...
1
vote
0answers
21 views

Does Trace Flag 8295 applies to SQL Server 2012?

I've been searching about the undocumented Trace Flag 8295. It's been introduced with KB 2476322 in SQL Server 2008 and "'Creates a secondary index on the identifying columns on the change tracking ...
0
votes
0answers
18 views

comparing left join and outer apply doing the same thing

I have an update trigger on a table that that insert rows in another database/table the query look like insert into otherdb.table select manyfield from inserted left join (select id, ...
0
votes
0answers
16 views

subscriber table needs to be updated - how to use a batch process AND how not to upset the replication while doing it?

I have a table called tblBOrderPaymentGiftVoucher that is replicated to 3 different subscriber servers. this table is part of a publication that contains many tables, some very big. I can't afford to ...
9
votes
2answers
322 views

In SQL Server 2016, what is the difference between Always Encrypted and Transparent Data Encryption?

As I write this I am still awaiting the official release of SQL Server 2016 so that we can explore the usefulness of its "Always Encrypted" feature. I would just like to know what the specific ...
0
votes
0answers
23 views

Mulit-part identifier could be found - Store Procedure

Hopefully I can get some sight into to what's going, Apologies for my lack of terminology and poor TSQL skills, I'm very much a developer that's inside an IDE and using ORM's. So I took the plunge to ...
0
votes
0answers
14 views

Can we track data changes on all sql tables based on primary-foreign key relationships?

Lets say I have a Customers table with primary key as Customer_ID and 10 more SQL tables with Customer_ID as foreign key. Without keeping triggers on all 11 tables, is there a way to track data ...
1
vote
3answers
41 views

SQL Server Select in XML field

I need a help with the situation below: In my table SQLServer 2012 have a field with xml values, I would like to make a select of the data in that field and show the result in the form columns. ...
0
votes
0answers
16 views

Tsql - getting list of instances in the alwayson Availability group

I want to connect to the listener in the AlwaysOn availability group and by running a query I will get the list of instances that are part of the AlwaysOn . For example: I has listener ...
3
votes
1answer
29 views

Howto query all files, their fill level and additional drive info with one query?

I need a query that puts together the following results: one row per databse file across all databases additional columns with information about the locigal drive the file is on information about ...
0
votes
1answer
45 views

SQL server auto update column

I am trying to change the value of defaults column from Y to N if a new value is inserted. The default column is now only restricted to have only 1 Y based on the different membershipType. The ...
1
vote
1answer
30 views

Data transferring

Is there any practices to transfer data from two databases that have different structure of table ? For example : old system : table [folder] with col: FolderId, name, age, sexe, date, orders New ...
5
votes
3answers
330 views

Why set Auto Update Statistics to False?

I've just inherited about 20 instances of SQL Server, as part of a wider acquisition project. I'm in the process of assessing performance and I don't like the way maintenance plans have been ...
0
votes
0answers
40 views

CTE query or sql query

I have two tables Table1 and Table2 Table1 Schema: Product | company | Demand...the demand is not present in table1. Table2 Schema: demand | company which contains demand ..... I need to update ...
-3
votes
1answer
37 views

SQL server automatically update table column

The default column is now only restricted to having only 1 Y based on the membershipType column. Now, i am trying to set my defaults column able to automatically change to N if there is existing Y. ...
0
votes
0answers
13 views

SSIS package for Table copy dynamically [duplicate]

I wants to copy a table structure along with data dynamically using SSIS 2012 from a DB server to another DB server. The server and database exist physically. The user would provide 5 parameters. ...
1
vote
3answers
55 views

How to find values from one table missing in another?

I am a Junior Developer. I have been asked to create a subquery to solve this problem. If the question is not clear please let me know so I can provide more details. I have two tables - Article and ...
1
vote
0answers
21 views

Find who started SQL Server Service

I found a situation where it would be useful to know who started SQL Server Service. First we did not know why it was stopped, it was not that urgent since this was a TEST instance but suddenly one ...
2
votes
1answer
13 views

Run Built-In Function on linked server

We have two SQL 2014 servers, and I have created a Linked Server on one of them to the other. As part of a task I'm trying to run I need to convert a SQL UserID to a username on both the local and the ...
1
vote
0answers
10 views

How to set ENVREFERENCE when creating a SQL Server job

SQL Server 2014 (if it matters) When I am migrating SSIS packages and jobs between environments, I need to update the /ENVREFERENCE parameter to the command for each job step. Is there anyway to ...
-1
votes
3answers
46 views

Exclude databases from automatic full backup

I have 10 databases on my SQL Server. We do an Automatic Full Backup every day at 00.00. The issue is there are two databases out of the 10 that should not be backed up as these databases are ...
1
vote
3answers
62 views

T-SQL for Query that can be done in SQL. What do they want?

We are given tables Vendors(VendorId, VendorName, ..) , Invoices(InvoiceId, VendorId...) I am going over a book exercise that asks for a T-SQL statement to find all vendors with at least one invoice. ...
4
votes
2answers
59 views

Queries without Good Enough Plan Found

I have a SQL Server 2012 database. I noticed value of Reason for early termination of statement optimization for some queries and all gave Good Enough Plan Found. Now my questions are: What are all ...
12
votes
8answers
2k views

T-SQL : Is string a Palindrome?

I am a beginner in T-SQL. I want to decided whether an input string is a palindrome, with output =0 if it is not , output =1 if it is. I am still figuring out the syntax. I am not even getting an ...
0
votes
0answers
19 views

Connecting 2 databases using sp_addlinkedserver

I have 2 servers and I want to connect to them using this: exec sp_addlinkedserver 'myserver1.dyndns.biz'; exec sp_addlinkedsrvlogin 'myserver1.dyndns.biz' , 'FALSE', NULL, 'remoteuser', ...
0
votes
0answers
27 views

Service Desk SLA Report

I need assistance with regard to a DBA task. I need to create an SLA report that will show incidents that were resolved after the SLA period which is 4 hours. I am using SQL Server 2014 with a Heat ...
6
votes
2answers
248 views

Table Relationship - One to Few (Many)

I know the title may seem confusing but I have yet to find a solid answer to this design pattern. Let's say I want to create an Employee table and have multiple addresses for each employee. So this ...
2
votes
1answer
27 views

Monitor if sqlserver is up from distant server using sqlcmd

I want to monitor if my sqlserver is up from a distant machine. I currently send a simple "select @@version" query with sqlcmd and then validate if that query returned the expected part of text : ...
0
votes
2answers
31 views

AlwaysOn Async read takes more time when compared to that of Sync secondary [on hold]

AlwaysOn Async read takes more time when compared to that of Sync secondary (by a small fraction). Is this expected behaviour? I was under the impression that ASYNC must be faster than the SYNC.
1
vote
2answers
107 views

Return multiple columns (int datatype) inside a CASE expression

How can I get multiple columns from a CASE expression? with cte as ( select ROW_NUMBER() over (order by id)'Rownumber', id from dbo.Test ) select case when (b.id-a.id) > 1 ...
0
votes
0answers
16 views

Error connecting from other SQL instance using powershell script

I have a job to run a powershell script that will rebuid fragmented index through source SQL instance to target SQL instance. The poweshell script didn't run due to the following error: Sqlcmd: ...
-5
votes
1answer
34 views

Disk Space issue [on hold]

I am facing one problem regarding Disk Space issue. One Disk size is 249 GB,it contains only .mdf files. Now the Disk utilization is 84%. How can i reduce Disk utilization less than 80%.
2
votes
1answer
42 views

What happens when two separate processes perform a full backup against the same database?

I have an instance of SQL Server 2012 RTM running. I have two separate applications that want to do a backup of a database lets call them "AppFull" and "AppFullCopyOnly". AppFull does a full ...
2
votes
2answers
68 views

Can we commit the transaction when the sql server trigger fails?

I am trying to avoid data loss when the insert trigger on a table fails. I am trying this with the following scenario and my code is failing. When an insert happens on the Customers table, I want to ...
1
vote
1answer
29 views

TSQL Solution to backup ALL databases on ALL instances of a server?

I'm pretty sure what I'm wanting with my current implementation is impossible, the sys.databases catalog view which is scoped at the service level to be aware of other SQL Server instances (lol). But ...
4
votes
1answer
80 views

Slow Delete's of LOB data in SQL Server

I have a tables for logging, and a stored procedure to purge old data that has very slow DELETE performance, beyond what makes sense to me. I am looking for how to modify the tables or DELETE ...
3
votes
1answer
32 views

Do temporal tables log changes when there are none?

Unfortunately I don't have ready access to a SQL 2016 instance to test this. If I had a temporal table with the following schema: create table blah ( foo int identity(1,1), baa int ) and I ...
1
vote
1answer
47 views

Slow-running query returns incomplete resultset

So I'm trying to get some data from an SQL Server 2008 instance, the query is quite simple in structure but it has an extremely poor performance, it takes just under a minute to retrieve a bit over ...
5
votes
3answers
181 views

Selecting one row from each group based on a Varchar field

Given a table Avenger whose data looks like this: id Avenger Type Power 1 Captain America foo 2 2 Captain America bar 3 3 Me foo 5 4 You ...
1
vote
3answers
44 views

how can database snapshot to be used to recover data?

I know the logic behind database snapshot and how it works. But my problem is how can database snapshot to be used to recover data? can we take a backup of database snapshot and restore it in a new ...
1
vote
1answer
24 views

Using a join operation with conditionals

I have two tables that I'm working with in my database. I am using SQL Server 2014. One is 'versions', that contains version_id, version_number, start_date, end_date and server_id. The other is ...