30 questions from the last 30 days
5
votes
3
answers
127
views
How to pick second value for same ID with other conditions
I have a Region table where MapID is the primary key. Each MapID can have EmployeeID or Zip5.
For any MapID, EmployeeID takes the precedence over Zip5 i.e. for any MapID, if there is an EmployeeID, ...
3
votes
2
answers
147
views
Return rows from a group of rows if a specific value does not exist within the group
Based on the table values shown below, I am trying to return all rows for each Name, Activity, and Date when 'No Activity' is not in the Activity column for those dates.
I attempted the following but ...
2
votes
3
answers
170
views
SQL Server stored procedure passed a Biztalk XML message not returning field values when parsing the XML text
Our integration team want to send a XML parameter from their Biztalk server containing values to be written to a SQL Server table using a stored procedure, and have sent me an example for me to create ...
2
votes
2
answers
151
views
Why does BULK INSERT require BULKADMIN permissions but BCP does not?
I noticed something strange regarding SQL Server bulk operations and permissions.
When I run this command inside SQL Server:
BULK INSERT dbo.MyTable
FROM 'C:\Data\file.dat'
WITH (DATAFILETYPE='native',...
2
votes
1
answer
105
views
Is it possible to use a SQL query for setting the AllowBlank property of a parameter?
Is it possible to set the AllowBlank property of a parameter in a SSRS report via SQL query?
I want to do this, because I have in the parameters one which is depending on another parameter.
When the ...
1
vote
2
answers
155
views
Combine Multiple Tables into Single Resultset
I have 4 tables with data shown here in SQL Server 2019 (RTM) -15.0.2005
Table 1: Buyer
ID
NAME
123
ABC
234
XYZ
456
MNO
Table 2: Sell Detail
Sl No
ID
TYPEID
A
123
1
B
123
2
C
123
3`
D
234
1
E
456
2
...
1
vote
0
answers
164
views
Using non hard-coded values for test conditions within VS SQL Server Unit Test Project
Is it possible to use non hard-coded values for asserting scalar values in VS SQL Server unit test project? Below I have the variable @ResourceId that I'd like to test against the value of a column ...
0
votes
2
answers
115
views
Stored procedure result truncates at 2033 characters [duplicate]
I am calling a SQL Server stored procedure from C#. It works fine as long as the result is not longer than 2033 characters. If it is longer than 2033 characters, the result is truncated at 2033 ...
0
votes
2
answers
121
views
How to perform skip and take in Linq with joining multiple tables in optimized way
How to write a linq query that does the same as this SQL statement:
select *
from [dbo].[LitEdit] as le
inner join [dbo].[LitEditJob] as lej on lej.BulkEditId = le.Id
inner join [dbo].[...
0
votes
1
answer
118
views
Convert Timestamp in dd-mmm-yy hh:mm:ss.sssssssss PM format to yyyy-mm-dd hh:mm:ss
In SQL Server 2019, I am trying to convert NVARCHAR(max) timestamps (ex. 02-DEC-25 05.27.13.318965000 PM) to datetime (ex. 2025-12-02 17.27.13). I have tried multiple methods and always seem to get ...
Best practices
0
votes
4
replies
139
views
How to ensure an inserted row survives a rollback?
In SQL Server, I have a stored procedure that returns some sensitive data to the client, and logs that fact into a log table. The stored procedure is executed in a transaction controlled by the client,...
0
votes
1
answer
86
views
SqlBulkCopy is failing to save records with an error "The given ColumnMapping does not match up with any column in the source or destination."
I have table defined like this:
CREATE TABLE [staging].[tbPositionAssetIdentifier]
(
[StageID] [int] IDENTITY(1,1) NOT NULL,
[AssetId] [nvarchar](50) NULL,
[SecurityDescription] [nvarchar]...
0
votes
1
answer
165
views
Convert a number stored as a string in SQL to a decimal
The data management company stored all of the numeric fields in a table I need as varchar, for some reason. As I work with them to try to get it fixed I still need to do my work so I am trying to ...
Best practices
0
votes
2
replies
96
views
T-SQL ETL update evaluation recommendation: What is the most elegant & performative way to evaluate a source value to update a target value?
What recommendations might be offered for the most elegant and performative way with T-SQL to evaluate whether a source value should update a target value, as part of an ETL update process in which ...
0
votes
1
answer
71
views
Joining 2 columns from 2 different tables to replace null values in one of the tables [duplicate]
I have 2 tables with a column called Participant ID. One table is completely null/empty in said column and the other table is filled. I would like to input the data from the filled table into the ...