Questions tagged [sql-server-2016]
Use this tag for questions specific to the 2016 version of Microsoft's SQL Server.
3,685
questions
6
votes
2
answers
65
views
Join tables but allow use of records once only
CREATE TABLE #A (UpperLimit NUMERIC(4))
CREATE TABLE #B (Id NUMERIC(4), Amount NUMERIC(4))
INSERT INTO #A VALUES
(1000), (2000), (3000)
INSERT INTO #B VALUES
(1, 3100),
(2, 1900),
...
-1
votes
1
answer
40
views
SQL How to find max date grouped by month where a value appears [closed]
I have a table that contains a date column, a code column, and an count column. Each day the table is updated and if there is something in the code column to capture, it is recorded. However, not ...
0
votes
2
answers
57
views
SQL Server sampling large volume of data per hour
Im using SQL Server 2016, and have a very large table containing millions of rows of data from different sources at irregular intervals over several years. The table cannot be altered, typical data ...
1
vote
0
answers
19
views
SSIS checkpoints are not re-starting correctly, skipping NON-checkpointed tasks
I have an SSIS package where the checkpoints are not behaving as I understand that they should.
To simplify, this is the kind of setup:
Imagine a package with two containers in a serial flow (...
1
vote
3
answers
68
views
SQL Server (terminal result) hierarchy map
In SQL Server 2016, I have a table with the following chaining structure:
dbo.Item
OriginalItem
ItemID
NULL
7
1
2
NULL
1
5
6
3
4
NULL
8
NULL
5
9
11
2
3
EDIT NOTE: Bold numbers were added as ...
0
votes
0
answers
13
views
Masking entire table with one line of script - Microsoft Dynamic Data Masking
is there a way in Microsoft Dynamic Data Masking (DDM) to mask an entire table in sql server with just one line of script using the same function for all columns? defining the masking rule on the ...
0
votes
0
answers
21
views
Invalid column name 'warehouse_name' [duplicate]
Please assist me to resolve the issue with this query below. It keeps telling me I have an invalid column name. When I run the query without the subqueries and the CASEs and GROUP BY, it gives me a ...
0
votes
0
answers
39
views
Cross Apply takes a while to load
I've been trying to optimize a web page for one our applications that takes a while to load. The original page was written with LINQ (it's .NET MVC Web Application) and I'm trying to write a query in ...
-1
votes
0
answers
20
views
TSQL Nested Cursor Error For Removing all Databases inside all the HA on Server Instance [closed]
I am trying to remove all the databases present in all the HA of a SQL Server Instance. I am using a Basic table named "AG_Info" having details of AG's and all DB's inside each AG.
I am ...
2
votes
1
answer
56
views
Coldfusion 2018 - sql server 2016 - Linked server to Oracle 12c - ANSI_NULLS and ANSI_WARNINGS error
We have 3 coldfusion servers. All of them have the same settings, as far as I can tell. The sql server connected has a linked oracle server, and when using OPENQUERY(), it sometimes throws this error ...
0
votes
1
answer
28
views
sql output json structure
I need to get the following output about the sql query:
{
"records": [
{
"attributes": {
"type": "customer"
}...
0
votes
0
answers
113
views
When I write a string to an image field in SQL it gets saved in UTF-16 LE encoding and I need it to be UTF-8
I have about 1200 databases in SQL 2016 Enterprise in which documents are stored as BLOB's in image fields in the database. I migrated all the documents to our Document Management System and now I ...
0
votes
1
answer
49
views
Calculating weekly Hires, Rehires, and Terminations from monthly snapshot
We have a table that contains a snapshot of every employees data at the end of each month until the month they leave the company. This table also has the snapshot of each employee for the current day ...
0
votes
1
answer
86
views
How to convert STRING_AGG to stuff function to work query on SQL Server 2016 below? [duplicate]
I have below SQL query which is not working on SQL Server 2016 and below version
SELECT
(
SELECT STRING_AGG(d.Name, ',') AS divnames
FROM (
SELECT div.name, MHLId
...
0
votes
2
answers
60
views
Loading data from an XML document (not a file)
I have a lot of logfiles that I want to load into a SQL Server database via a Talend job so that I can preserve the logs without keeping the files in the file system (we generate over 3k log files ...
0
votes
0
answers
54
views
Using SQL Server to Export one table to data from a database to the same table in another database on the same SQL instance
I am using SQL Server Management Studio Export Data from one database to another on the same server. Everything ran
fine except the table below is taking hours to run. I have large tables that have 20,...
0
votes
2
answers
28
views
Select the Upcoming Pay Date of the Current Month AND Year
I have a table that only contains pay dates:
Pay Date
03/05/2022
03/25/2022
04/20/2022
Sometimes there are two pay dates in the same month. I’d like for my query to return the upcoming pay date ...
0
votes
0
answers
71
views
Windowing functions perform poorly after upgrade from SQL Server 2012 to SQL Server 2016
I am currently involved in the upgrade of a server from Microsoft SQL Server 2012 to 2016. Following the upgrade, we are finding that objects with windowing functions are behaving very poorly.
By &...
0
votes
1
answer
32
views
How to insert rows into a SQL table with a SELECT NOT EXIST statement from one server to another?
My goal is to look on ID column in TableA -> ServerA and then if there are any new records that program could find in TableB -> ServerB that are not in TableA -> ServerA, insert those into ...
0
votes
2
answers
52
views
Generate a sequence in SQL based on the column values
I need to generate a sequence in SQL Server 2016 database based on the following logic.
I have three fields each represents ID of Brand, Category and the Product. A brand could have multiple ...
0
votes
0
answers
37
views
Query to highlight if a row is deleted from table
I need to create a report/alert that advises me if a row of data is removed. The data comes out of a case management system in a fixed format -
SELECT 70383 AS field_id
, 'Demo_field' AS ...
0
votes
2
answers
109
views
SSIS Package to copy data from one to another error
I have setup a SSIS package to copy over some data from one table to another. At first I tried doing from one server to another server, did not succeed. Then I tried it doing within the same server, ...
0
votes
5
answers
94
views
How do I keep all values FROM Table 1 while joining multiple tables with conditions to Table 2, which has a LEFT JOIN to Table 1?
Requirements: Have all the customers listed from the first table, then pull any classes that match conditions from the second table and third table, with the third table joined only to the second.
...
0
votes
0
answers
49
views
Unable to import SAP ECC data using SSMS
I'm trying to follow this tutorial Import SAP Data Using SQL Server Management Studio (Microsoft.com)
However, after I did the Step 5 "Choose a Data Source", the "Import Data" ...
-1
votes
1
answer
57
views
Insert stored procedure result into dynamically created table [duplicate]
I want to insert the stored procedure result set into a table. Is it possible to create a table dynamically? Columns may vary so please help.
This is my stored procedure result set where columns BYL, ...
0
votes
1
answer
32
views
DateTime coming as '11.22.2022 09.10.00' and sql update query failing
For one the production system, different date/time format I am getting data time like 11.22.2022 09.10.00 and when try to run below sql query I am getting error The conversion of a varchar data type ...
0
votes
0
answers
27
views
SQL Server 2016 distinct and trim not removing left empty space
BEGIN
SELECT DISTINCT(line_of_bus)
FROM contract_info
WHERE line_of_bus IS NOT NULL
AND TRIM(line_of_bus) <> ''
AND contract_yr = i_year
END
I have a value that has a ...
0
votes
1
answer
25
views
Run stored procedure for multiple rows & record success/failure?
I have the below table which gets loaded into my DB each night (this usually contains more rows, but I have just included 2 for example).
I then have a stored procedure called [dbo].[StitchUsernames] ...
0
votes
0
answers
12
views
Amend custom URL for SSRS server
I have a server running SSRS. Visiting the server URL directs to the intranet URL:
http://server/CloudReports/Pages/Folder.aspx
I believe the 'CloudReports' folder name was customised previously but ...
1
vote
2
answers
38
views
iTVF for splitting string into row of substrings based on a specified separator character breaks when received empty value (TSQL)
I have an inline table-valued function, which splits strings into row of substrings based on a specified separator.
It is as follows:
ALTER FUNCTION [dbo].[SplitString]
(@List NVARCHAR(MAX),
@...
0
votes
1
answer
63
views
Why doesn't user in SSIS database role db_ssisoperator see any projects in the Integration Services Catalog?
I am trying to give a user (AD Group) the ability to list all Integration Services Catalog projects and packages, execute all packages, and read the package logs. I DO NOT want them to be able to ...
-1
votes
1
answer
121
views
The argument 2 of the "JSON_VALUE or JSON_QUERY" must be a string literal
I am passing this JSON to a stored procedure in SQL Server
{
"individual": [
{
"app_id": 1057029,
"size": 2
},
{
...
0
votes
0
answers
19
views
SQL to JSON with multiple nested arrays at same level
I'm using SQL Server 2016 to create a JSON file with multiple nested elements. The final JSON needs to have two nested arrays on the same level, as in array1a and array1b in the simplified example ...
0
votes
0
answers
24
views
How to search a combined cell value with another value (text + text)
First time posting and not a SQL expert by any means!
Aim: I want to combine multiple row values (b.[Canvasser Name]) into one combined cell (f.canvassers) and check f.canvasser doesn't contain the ...
0
votes
1
answer
60
views
Calculate time difference by filtering and combining related entries from same table
I have the following table
TicketID
Operator
Datestamp
Remarks
1
p1
July 20, 2022, 10:30 PM
Changed from State A to B
1
p1
July 20, 2022, 11:30 PM
Changed from State B to C
1
p2
July 21, 2022, 10:...
0
votes
2
answers
54
views
T-SQL Query - how to create a new temporary "location" in a table under a location column that combines other location data
While running a query that selects a Location, date, and visitIDs, I need to be able to select a new combined location name (eg. "LOC3+4") which includes all the rows from locations "...
1
vote
1
answer
32
views
T-SQL - Query data based on different filter granularity
-- Data Setup
DECLARE @Table AS TABLE
(
[Id] INT IDENTITY(1, 1)
, [Type] TINYINT
, [TypeOne] INT
, [TypeTwo] INT
, [TypeThree] INT
) ;
INSERT ...
0
votes
1
answer
50
views
SSIS - Is it possible to fetch Remote SSIS Package (Stored in SSISDB) From Local Server, And execute on the Local Server
We have an ETL-DB Server (SQL Server 2019) - installed with SSISDB and SSIS Service. As per our new company DBA policy, ETL Server will be treated as DB Server and no more allowed to install our ...
0
votes
0
answers
30
views
Why is the SSRS Barcode breaks up with a space in between?
I have a SSRS report which I've initially created with SQL Server 2014 Report Builder (12.0.6024.0) using Code128 according to this post. It has been working great until we wanted to upgrade our SQL ...
0
votes
3
answers
51
views
SQL obtain values between second and third forward slash
In SQL Server, I am trying to obtain the values between the second and third forward slash (/) character. The length of the numbers can vary so substring(column, 8, 10) wouldn't work.
123/123/...
1
vote
1
answer
52
views
SQL Calculating Hourly Sales
I am trying to create a SQL report that shows hourly sales. This is from my POS system.
There's a built in table that has basically all the data I need, I'm just struggling to calculate the sum of a ...
0
votes
1
answer
53
views
SQL Server workaround for execute as user=?
I inherited a very non-normalized SQL Server database. The setup is such that every plant at this company has it's own schema within the database. Inside each schema, there are a few important ...
0
votes
2
answers
29
views
Convert multiple rows with a comma seperator value by performing Group By Operation
I have a table with Contract_Id, Site_Name, and Hours columns… and now my requirement is to generate the comma seperated values by performing Group By on Contract_Id column.
Contract_Id Site_Name ...
1
vote
2
answers
48
views
TSQL using modify to initialise a null column
Using TSQL modify how can I initialise a null column with a root XML element, and use the value of a column to create/populate a nested element?
From what I can tell, there's no way to create a root ...
1
vote
2
answers
47
views
How to return results that have multiple records tied to it, filtering out the rows that only have 1 result
PayID
userclass
category
paydate
90
111
7
1/1/2022
91
111
7
3/1/2022
92
222
8
2/1/2022
93
333
8
2/1/2022
94
444
9
3/15/2022
95
444
9
4/1/2022
So I want to write a SQL query that allows me to ...
0
votes
1
answer
51
views
Identify which columns are different in the two queries
I currently have a query that looks like this:
Select val1, val2, val3, val4 from Table_A where someID = 10
UNION
Select oth1, val2, val3, oth4 from Table_B where someId = 10
I initially run ...
0
votes
0
answers
26
views
Setting SQL Server Agent to run an SSIS package on a target server version
I deployed an SSIS package to SQL Server 2019. The target server version on the package is SQL Server 2016 because there is a custom component in the package that is not compatible on 2019.
When I ...
-1
votes
1
answer
75
views
Keep only allowed characters in a string
If I know which characters I do not want to keep in my string I can easily remove them with REPLACE:
SELECT REPLACE(
REPLACE(
REPLACE(
'String with characters like #§$ ...
0
votes
0
answers
40
views
Check activity of SQL DB
I need to check if a SQL DB (SQL Server 2016) is still in use. Well, how can I get it?
My approach is to check all logs to verify if someone is still inserting, deleting, selecting data and so on.
For ...
1
vote
1
answer
24
views
Update the Indicator column based upon the Id Column by Incrementing of 5 numbers
I have a table with Id, Site_Name, MEMSUB and Indictaor columns… now my requirement is to update the Indicator column based upon the Id Column
Below is my table,
Id Site_Name MEMSUB Indicator
1 ...