Q&A archive

Stack Exchange Answers

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

DBA Stack Exchange

How do I preserve leading zeros for varchar field?

Question When saving a number with leading zeros into a string variable or column, leading zeros are truncated. When I run this query: declare @varchar as nvarchar(50) set @varchar = 011 print @varchar The result I get is 11. Is there any way to get 011?

Read answer

Stack Overflow

How to convert from nchar to decimal in SQL?

Question I have 2 tables(source and destination) which are respectively NOR_LABOR and ALL_LABOR_DETAILS. In the source table(NOR_LABOR) there is a column feet_produced with the data type nchar(10). In the destination table(ALL_LABOR_DETAILS) there’s a column …

Read answer

DBA Stack Exchange

View SQL Code Behind Flat File Import Wizard?

Question Is there a way to view and copy the code that the "Import Flat File to SQL" Wizard ultimately uses, after I have gone through all the steps (chosen file, set up data types for my columns, etc.)? While using the Import Flat File to SQL wizard, I found …

Read answer

DBA Stack Exchange

Cardinality , Parallel Hint alternative for MS-SQL

Question UPDATE MARK M SET ARCHIVE_FLAG = 'N' WHERE EXISTS (SELECT /*+ cardinality(S1, 10) parallel(S1,8)*/ 1 FROM SHFASG S, SHIFT S1 WHERE S.ID = S1.ID AND M.ID = S.MARKID AND ARCHIVE_FLAG <> 'Y'); This is the oracle query that I have, I want to create …

Read answer

DBA Stack Exchange

log send queue size and redo queue size in AG

Question I am trying to figure out the way to monitor these 2 events log send queue size - I can see this in perfmon Redo queue size - I can see in dmv but not in perfmon counter Is there any way of using perfmon so that I can calculate the redo queue size …

Read answer

Super User

Is my VM hyperthreaded?

RonJohn needs to know if his VMs are hyperthreaded. I point him to vCenter for a definitive answer, and to a SQL Server DMV for the next best thing.

Read answer

DBA Stack Exchange

Replication of only updates and inserts

Question I have two sql servers, in the first I want to keep the data from the last three months and in the second I want to keep all the data with the purpose of getting historical reports. I know how to do a transactional replica but I don't know how to …

Read answer

DBA Stack Exchange

How to dig deeper into ASYNC_NETWORK_IO waits

Question I've been handed a graph that comes from SolarWinds showing top wait events broken down by day. The last 2 days there's a part of the daily color coded bar representing a total of 3 hours for ASYNC_NETWORK_IO. Still trying to see if I can get access …

Read answer

Stack Overflow

Recursive CTE in SQL Server to count blocking sessions

Question I’m trying to make CTE to count blocking sessions on server. Currently I made a function to do so(returns blocking session amount). But still could not write this query with CTE. CREATE FUNCTION dbo.SESSIONS(@SESSION int) RETURNS INT AS BEGIN DECLARE …

Read answer

DBA Stack Exchange

How to store real-time data to database

Question Here is my situation: I have a WebSocket connection that feeds me data real-time I have an async callback function that gets the data and inserts into a queue I have another thread that reads from the queue and stores it into the Postgres database, …

Read answer