336,374 questions
0
votes
1
answer
104
views
If product code does not exist in first part of query pull a declared value from another table for that product code
The first table I have stores fixed prices on product codes SellPriceRule and I show the query I have to get the list I want. The problem is for certain customers - using 1 as an example 7000192 - the ...
0
votes
1
answer
138
views
Add a column to select query but exclude from grouping
I have the following query:
SELECT
MAX(F.Surname + ', ' + F.First_Name) AS Female,
ISNULL(MAX(M.Surname + ', ' + M.First_Name),'') AS Male,
MAX(CP.Comp_Date) AS Comp_Date,
H....
0
votes
0
answers
95
views
Legacy SQL Server jobs for data migration issues [closed]
We handle data migrations using scheduled SQL Server jobs.
A month ago, I got a new requirement to migrate the last_add2, batch_no_all, and box_num2 values from a remote database. I updated the stored ...
Advice
0
votes
2
replies
64
views
Copying data from Oracle to SQL Server, with logic to reorganize data
My company has a customer that holds a large amount of data in the Oracle NetSuite product. This uses a very complicated data model. For fast reporting of the data, my company has provided our ...
Advice
1
vote
4
replies
140
views
How to show only the first instance of a SQL count?
In SQL Server, I have table myTable with fields patientID, orderID, and orderDesc. patients can have multiple orders with individually variable descriptions.
I’m requested to write a query to select ...
Advice
0
votes
1
replies
74
views
Using timeout for Python's pyodbc
I am working on a project where I would need to query from MSSQL server. I am using Python and pyodbc for the work, and I want to use timeout for QUERY EXECUTION. But there is no direct way. Is there ...
-2
votes
0
answers
108
views
Create DSN for SQL Server with Username and Password
How to automatically create DSN for connection to SQL Server with supplied username and password?
The following code I have used worked if I am not supplying username and password, but I need the one ...
-11
votes
0
answers
136
views
Movie recommendation database - select top movies [duplicate]
create table Movies
(
movie varchar(100),
genre varchar(100)
)
create table Actors
(
actorName varchar(100),
movie varchar(100)
)
create table Users
(
userName varchar(...
2
votes
1
answer
121
views
Unexpected behavior with using a CTE to update a temp table
DDL:
IF OBJECT_ID('tempdb..#Tab2And3Pop') is not null
DROP TABLE #Tab2And3Pop;
SELECT CAST(115704 AS INT) AS ConflictNoticeID
, CAST(16003573 AS INT) AS MerchantID
, CAST(13 AS ...
Advice
0
votes
8
replies
86
views
T-SQL hint to block key lookup, without forcing a particular index
Is there an index hint in T-SQL that says "do not use any nonclustered index that would require a key lookup"? Apart from that one restriction, I want to let the query planner have a free ...
1
vote
2
answers
190
views
Query `select count(distinct columnname)` returns zero for non-admin user
For a non-admin user, with 'Select' permissions on a 'View', they are able to count the number of rows and display all the contents of a SQL 'View':
select * from dbo.BackupInfoView;
select count(*) ...
Advice
0
votes
5
replies
144
views
Is there a more efficient way to dedupe records in my query?
I have a query that pulls in the account number, service date, and 20 other fields. Some accounts have several service dates, so I need to return only the most recent one for each. Here is a slimmed ...
1
vote
2
answers
111
views
How to extend subset of products by ones determined by few product groups?
The subset of products - reduced for categories and product lines assigned to the user - should be extended by products from explicitly named groups.
So far, the following code works:
products = ...
0
votes
1
answer
86
views
ConnectionError: Failed to connect to localhost/SQLEXPRESS01:1433
I am trying to build a web API using Express + Typescript using this Github repo as a starting point. I am using the mssql package with the default tedious driver.
This is my config:
server: '...
0
votes
0
answers
81
views
Use of variable and outer join inside a trigger causing error "Cannot continue the execution because the session is in the kill state."
With compat 170 (in SQL Server 2025), I'm seeing "Cannot continue the execution because the session is in the kill state." when using an outer join with a variable as part of the join ...