Q&A archive

Stack Exchange Answers

Questions and answers Andy Mallon contributed across the Stack Exchange network.

DBA Stack Exchange

Using OPENJSON, can't get results to GROUP BY

Question I'm passing a JSON string to a stored procedure in order to insert warehouse inventory. Sometimes, there will be multiple line items with the same product, going to the same shelf, on the same pallet (LPN), with the same date. I would like to …

Read answer

DBA Stack Exchange

SQL Modulo Function gives the wrong value?

Question In Javascript, Excel, Python, and a scientific calculator, the modulo operation -34086.1576962834 % 360.0 <-- python =MOD(-34086.1576962834, 360.0) <-- Excel function gives a value of 113.84230371659942. (Or something very close to that, depending on …

Read answer

DBA Stack Exchange

What's the use case of disabling an index?

Question I just learned that indexes can be disabled on a table. Even the clustered index can be disabled. After that, users can’t access the index or the data if clustered index. When will we disable an index? I just don’t understand the use case.

Read answer

DBA Stack Exchange

snapshot replication - corrupted BCP files

Question Each night my SQLServer replication failed on a big table with the following error. It is failing on a different table each night but always on a relatively big table ( > 200,000 rows) The process could not bulk copy into table '"dbo"."Table01"'. …

Read answer

DBA Stack Exchange

Temporarily turn on Cascade Delete

Question This has probably been asked before, but I couldn't find the answer. I have a complex datamodel in sql-server-20XX (more likely to be something old) in which cascade delete has been turned off (by design). A large chunk of our database has been sold …

Read answer

DBA Stack Exchange

SQL Main query value used in the WHERE in the subquery

Question I'm really confused by this SQL here, I have this sample where I am using the value from the main query in the subquery and then using XML PATH to add a comma between the dates. The setup is 2 tables one with the dates I want to string together. I am …

Read answer

DBA Stack Exchange

CASE statement issue

Question Can anyone help with this error? SQL: SELECT InvoiceDate, BillingAddress, BillingCity, Total, CASE WHEN Total < 2.00 THEN 'Baseline Purchase' WHEN Total BETWEEN 2.00 AND 6.99 THEN 'Low Purchase' WHEN Total BETWEEN 7.00 AND 15.00 THEN 'Target …

Read answer

DBA Stack Exchange

Which install kit installs sqlcmd.exe?

Question I recently had to uninstall Visual Studio 2012 and DTS, then install VS 2017 and DTS again. Afterwards, The directory containing sqlcmd.exe was not in my PATH variable. I installed the following. vs_Professional-vs2017-15.9.41.exe …

Read answer