Forum Widgets
Latest Discussions
Can a T-SQL procedure copy content of an Excel sheet to another Excel-файл?
Is it possible to create a T-SQL procedure that would do the following: Open an input Excel-файл; locate a specific sheet there; Open an output Excel-файл; locate a specific sheet there; Copy the whole content of the input file sheet into the output file sheetю ?SolvedVictor_SotnikovAug 18, 2025Copper Contributor45Views0likes1CommentTrigger is hanging up the database
Hi, I need to send a database email when the status field of a newly inserted field is <> '0'. I have a trigger that works fine at another location but will cause the database to not populate when enabled at this location. I have tested the database email and successfully sent and received an email from a query using EXEC msdb.dbo.sp-send-dbmail and the lines to follow as seen below in the code. If I just run the query the email goes out, but when I use it as a trigger just enabling it causes the database to hang up. USE [AK_Mid_TV] GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO ALTER TRIGGER [dbo].[TV Front Image Alarm Alerts] ON [AK_Mid_TV].[dbo].[TV Data] FOR INSERT AS SET NOCOUNT ON; DECLARE @tableHTML NVARCHAR(MAX); SET @tableHTML = N'<h1>TORPEDO VISION FRONT ALARM ALERT</H1>' + N'<table border = "1">' + N'<tr><th>Car ID</th><th>Image Time</th>' + N'<th>Front Alarm Level</th><th>Front Alarm Temp</th><th>Direction</th>' + CAST ( ( SELECT td = dbo.[TV Data].[Car ID], ' ', td = dbo.[TV Data].[Image Time], ' ', [td/@align] = 'center', td = dbo.[TV Data].[Front Image Alarm Status], ' ', [td/@align] = 'center', td = format(dbo.[TV Data].[Front Temp F], '#,#'), ' ', [td/@align] = 'center', td = dbo.[TV Data].[Direction Label] FROM dbo.[TV Data] where [Image Time] in (SELECT MAX([Image Time]) from dbo.[TV Data]) and [Front Image Alarm Status] <> '0' FOR XML PATH ('tr'), TYPE ) AS NVARCHAR(MAX) ) + N'</table>'; If @tableHTML <> ' ' EXEC msdb.dbo.sp_send_dbmail @profile_name = 'Alarm emails', @recipients ='email address removed for privacy reasons' @copy_recipients = 'email address removed for privacy reasons', @subject = 'TV Alarm Alert', @body = @tableHtml, @body_format = 'HTML';SolvedBMichelleJul 03, 2025Copper Contributor158Views0likes5CommentsSql to calculate quarterly/annual aggregation aside of monthly numbers
Hi, I am struggling to calculate amounts based on mtd amounts w/o using a cursor. Any idea? create table #raw(quarter int, name varchar(10), year int, month int, amount decimal(19,2)) insert #raw(quarter, name, year, month, amount) values(1, 'aa', 2025,1,2.0),(1, 'bb', 2025,1,4.0),(1, 'cc', 2025,1,1.0), (1, 'aa', 2025,2,6.0),(1, 'bb', 2025,2,8.0), (1, 'aa', 2025,3,10.0),(1, 'bb', 2025,3,2.0),(1, 'dd', 2025,3,4.0), (2, 'ee', 2025,4,9.0),(2, 'bb', 2025,4,3.0),(2, 'cc', 2025,4,3.0),(2, 'aa', 2025,4,1.0), (2, 'ee', 2025,5,15.0),(2, 'bb', 2025,5,1.0),(2, 'cc', 2025,5,2.0),(2, 'aa', 2025,5,7.0), (2, 'cc', 2025,6,8.0),(2, 'aa', 2025,6,9.0) Annual calc is easy, but not sure how to add quarterly number aside: select mtd.quarter, mtd.name, mtd.year, mtd.month, mtd.amount, sum(ytd.amount) as ytd from #raw mtd join #raw ytd on mtd.name = ytd.name and mtd.year = ytd.year and mtd.month >= ytd.month and mtd.quarter >= ytd.quarter group by mtd.quarter, mtd.name, mtd.year, mtd.month, mtd.amount order by 1,3,4,2 Goal is to get a report like this:SolvedEdSpa290Jun 19, 2025Copper Contributor85Views0likes2CommentsAnalysis Server Roles from Entra workstation
We have Analysis Server solution, maintained and deployed from Visual Studio, where the roles defined use AD groups. This worked perfectly as long as long as the machine used was on the same domain as the groups or was hybrid joined. On a new laptop that is Entra-only joined we do see a curious issue. The AD where the groups are located is a fully trusted domain. In SSMS (version 20.2) we now see this behavior in the Object Explorer: Connect to SQL Server Database Engine On-premise server A Navigate to Security -> Logins -> Right-click and select New Login Click on Search Click on Locations Full list of available domains to search is available Connect to SQL Analysis Services On-premise server A (so the same server) Navigate to Databases -> {Database name} -> Roles -> Right-click and select New Role Click on Membership and Add Click on Locations Only the local computer is available This prevents us from creating new roles with an AD group membership. Please note that everything else is working fine. Browsing as another AD user in any way works perfectly. Any ideas to why it behaves differently when connecting to database engine versus analysis services or what we can do to resolve this issue? PS! We see similar issues in Visual Studio if we try to edit roles in a Analysis Services Project. The assumption is that these both rely on the same underlying services to lookup objects on the AD domain. Thus if we resolve the SMSS issue we hope that also resolves the VS AS project issue. Regards, StigSolvedStigJJun 18, 2025Copper Contributor92Views0likes2Commentsproblem restoring a backup
I have a backup file (xxxx.bak) in my c:\trmp directory. When I launch SSMS signed on as "sa" and try to restore this database, i get this window: I am not able to enter anything for "Database" and the dropdown is empty. Then if I switch it to "Device" I get this window: Now, under "Destination" I am able to enter a database name, i.e. the name I want the database to be referred to after I restore it. However, note the message at the top of the window: No backupset selected to be restored. How do I resolve this issue? MurraySolvedMurraySobol985Jun 06, 2025Brass Contributor213Views0likes8CommentsUnable to restore a backup
I have a backup named: xxxx.bak currently in my Temp directory. This backup was made from SSMS V20. I recently installed SSMS V21 and unable to restore this backup. Steps to reproduce: Open SSMS connected as "sa" Highlite "Database", right click to select "Restore Database" The window opens, I choose "General" under "Select a page", no "databases" are listed. I then switch to "device", again no "databases" are listed. I then look under "Destination, there are several database listed there but not the one I wish to restore. I'm not sure what step, if any, that I am missing. MurraySolvedMurraySobol985Jun 05, 2025Brass Contributor51Views0likes1Comment2025 Preview, Polybase unsupported connector location prefix
I've installed the preview version of SQL Server 2025 with Polybase enabled. We're currently using it on SQL Server 2022. Every variant I've tried to add a datasource results in the same error (e.g.) "'odbc://localhost' contains an unsupported connector location prefix. Refer to product documentation for a list of supported connector location prefixes." This applies for both odbc:// and sqlserver:// I've also tried different variants with CONNECTION_OPTIONS that both contain a Driver reference of a DSN reference. Everything results in the same error.SolvedgadeynebramMay 28, 2025Copper Contributor136Views0likes1CommentSQL Server Manager Studio V21 failed to install Configuration Manager
I installed SQL Server Management Studio V21 specifically: Step 2 - Determine which version of SQL Server Management Studio to install Decide which version of SSMS to install. The most common options are: The latest release of SQL Server Management Studio 21 that is hosted on Microsoft servers. To install this version, select the following link. The installer downloads a small bootstrapper to your Downloads folder. It downloaded a file: vs_SSMS.exe which I clicked on and "run as Administrator". FYI: It used the Visual Studio installer which I do NOT like since I was not able to follow the progress of the installation. After the installation completed I tried to connect as "sa" with my password and got this message: See SQL Server V21 error.png SQL Server is installed locally on my laptop, not on a network. I want to change to use TCPIP protocol for my connections. Also, when I looked at "Services" I did NOT find a service for Microsoft SQL Server. Any assistance would be appreciated. Thanks MurraySolvedMurraySobol985May 26, 2025Brass Contributor310Views1like6CommentsError when trying to create a Trigger
Hi I am trying to create a trigger so when a value changes from null to a value it copies the value into another field. However, I am getting errors on the basic code like BEFORE. Any ideas why? Thanks AaronSolvedAjcbutlerSeikiApr 11, 2025Copper Contributor137Views0likes4CommentsHow to create a view with unique record based on date
I have an EMPLOYEE table that looks like this: EmployeeID,Name,PositionID,HireDate,PositionStatus E001,Chelsey,P123,2013-11-23,Terminated E001,Chelsey,P234,2019-03-13,Active E002,Mike,P345,2014-03-23,Terminated E002,Mike,P345,2021-10-13,Terminated E003,James,P543,2015-01-12,Active E004,Samantha,P895,2018-12-13,Terminated E004,Samantha,P430,2020-05-21,Terminated E004,Samantha,P945,2022-06-16,Active E005,Kayla,P459,2023-03-13,Terminated As you can see, the EmployeeID can have duplicate. The reason for this is, there's a secondary ID called PositionID, which essentially describes the employee's role. For example, whenever an employee gets promoted, or moves to a different department, a new record will be created for them with the same EmployeeID but a different PositionID. When that happens, the Position Status of the older role gets set to Terminated, and the new one gets set to Active. The HireDate represents the date teh employee started working in that role. I would like to create a VIEW to filter this to have only the unique employees, based on the HireDate. If there are multiple records for the same employee, I want the view to show only the record with the most recent HireDate. The resulting table should look like this: What's the best way to go about this?SolvedSach-SGApr 01, 2025Copper Contributor93Views0likes2Comments
Resources
Tags
- Data Warehouse70 Topics
- Integration Services63 Topics
- sql server59 Topics
- sql47 Topics
- Reporting Services44 Topics
- Business Intelligence38 Topics
- Analysis Services33 Topics
- analytics23 Topics
- Business Apps22 Topics
- ssms15 Topics