Here's a few of the new posts today on the forums. To see more, visit the forums.
|
SQL Server 2017 - Administration |
Can not Truncate the database because “Secondary has no log was added” - I got an error when trying to truncate the database: "Database can not shrink until all secondaries have moved past the point where the log was added". When I check the status of the secondary on the primary machine (Always On High Availability Dashboard), it has heath: good and Synchronization state: Synchronizing. But the status […] |
SQL Server 2016 - Development and T-SQL |
Hierarchy related calculation - Hello all, I have a hierarchy of businesses. example can be created as follows: create table #temp (LeafLvl varchar(20), L1 varchar(20), L2 varchar(20), L3 varchar(20), L4 varchar(20), L5 varchar(20)) insert into #temp (leafLvl, L1, L2, L3, L4, L5) select 'L2-1', 'Top', NULL, NULL, NULL, NULL UNION ALL select 'L3-1', 'Top', 'L2-1', NULL, NULL, NULL UNION […] |
SQL Server 2019 - Administration |
Looking for recompiling stored procedures - I have been tasked with the job of finding the top X number of stored procedures that are being recompiled regularly on a group of servers. I've tried several times to Google this and keep coming across "How To" articles on setting stored procedures for recompile, which is not what I want. I'm trying to […] |
if then else issue - I'm trying to use the if then else to check if a member exist in a server role. if it does, do X, else do Y. but not getting the desire outcome. BEGIN DECLARE @member nvarchar(50); USE [master] SELECT @member = members.name FROM sys.server_role_members AS server_role_members INNER JOIN sys.server_principals AS roles ON server_role_members.role_principal_id = roles.principal_id […] |
Can not Truncate the database because “Secondary has no log was added” - I got an error when trying to truncate the database: "Database can not shrink until all secondaries have moved past the point where the log was added". When I check the status of the secondary on the primary machine (Always On High Availability Dashboard), it has heath: good and Synchronization state: Synchronizing. But the status […] |
SQL Server 2019 - Development |
Count Number of Records - Hi I am trying to write a SQL query that returns the number of working days between two dates. The approach I am taking is the following... Financial markets are open on non-holidays so doing a select distinct on trade dates would give me the list of all non-holiday dates. I could create a separate […] |
Find the records based on group by Student ID - Data looks like below Status 1 is Active and 2 is Clean For one Student ID we may have one active, one clean status; I want to find the records only with Clean status for a student ID. Student Id Student_Status 12345 […] |
problem of slowness in my requests - hello, I am having a major performance issue , with this part of code which is still blocked on my server , Attached is the part of the code that is causing the problem. DELETE R FROM #RESULTS_DEM AS R INNER JOIN dbo.Dem_trans AS DEM ON DEM.NUM_DEM = R.NUM_DEM WHERE ( NOT EXISTS ( SELECT […] |
Joining CTEs Causing Performance Issues - Hi everyone I am not sure why the query is taking so long to run. If I run each CTE separately then it runs in less than 2 seconds. However, when I join them they take forever to run. I stop the query after about 10 minutes. I am pretty sure I am joining them […] |
Need to create a .xml file in specific format using SQL Query. - I have a table of data that I need to create a .xml file from in a specific format. CREATE TABLE [dbo].[XML_TABLE]( [ProductID] [nvarchar](25) NULL, [Name] [nvarchar](25) NULL, [ParentID] [nvarchar](51) NULL, [AttributeType] [nvarchar](10) NULL, [AttributeID] [nvarchar](255) NULL, [AttributeValue] [nvarchar](4000) NULL ) ON [PRIMARY] GO Here are some values to insert: INSERT INTO WORK.DBO.XML_TABLE([ProductID], [Name], [ParentID], […] |
SQL Azure - Development |
Copy DB from Prod to Test !! - Good morning. I would like your advice. I work on Azure Sql. We have 3 environments (Dev, Test and Prod) Each environment has a specific tenant. Every month, I would like to copy the database from Production to the Test environment. What solution do you recommend to perform this task? Regards |
SSRS 2014 |
Open linked report in new tab with multiple parameters (javascript) - I have a report that links to another report on the server, while the way I have it currently works the users are requesting that it opens in a new window. The report being linked to has two multi select parameters ="javascript:void(window.open('http://east-rpdb01/reports/report/Testing/Profitability%20Report%20All%20Clients&FiscalYear=" & Fields!FiscalYear.Value &"'))" I am close to getting this but not sure […] |
General |
cross join sql - I'm attempting to use INNER JOIN to join numerous tables. Here is the code: IF OBJECT_ID('tempdb..#tmpRecData') IS NOT NULL DROP TABLE #tmpRecData --STEP 1 SELECT DISTINCT pr.ChainID, pr.StoreID, pr.SupplierID, pr.ProductID, MAX(CAST(pr.ActiveLastDate AS date)) AS 'Active Date' --ChainID, SupplierID, StoreID, InvoiceDate, InvoiceNumber, SupplierInvoiceDate, SupplierInvoiceNumber INTO #tmpRecData FROM dbo.[ProductPrices_Retailer] AS pr LEFT JOIN ProductIdentifiers iden ON pr.ProductID […] |
Anything that is NOT about SQL! |
Need information on past SQL Summits, please... - I'm endeavoring to convince my employer to send me to SQL Summit this year, but I'm going to need to "sell" that it would be worthwhile for them to do this. And sell it not just to my supervisor, but to his supervisor and to her superior. Now, I fully expect that there's going to […] |
SQL Server 2022 - Development |
The place of SMALLDATETIME - SMALLDATETIME is a datatype that gets very little love online and few people recommend it. Kendra Little is right to warn about the rounding up/down of seconds. Microsoft explicitly recommends DATETIME2 over SMALLDATETIME on the Microsoft Learn page. However, it is only 4 bytes in length and gives accuracy to a minute and DATETIME2(0) is […] |