Recent 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ю ?Solved56Views0likes1CommentTrigger 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';Solved171Views0likes5CommentsSql 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:Solved89Views0likes2CommentsAnalysis 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, StigSolved98Views0likes2Commentsproblem 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? MurraySolved230Views0likes8CommentsUnable 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. MurraySolved57Views0likes1Comment2025 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.Solved147Views0likes1CommentSQL 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 MurraySolved365Views1like6CommentsHow 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?Solved97Views0likes2CommentsRounding issue - expected or bug?
Hello, we use SQL Server 2019 and we got some unexpected rounding issues. See example: It is only example with numbers, in our situation there were sub selects with data types: 0.4399 = decimal(20,4) 33.00 = decimal(20,2) 1 = smallint. My question is, why in first and fifth selects is result only with 2 decimal and not 4 based on first number with data type decimal (20,4)? I have tested it with latest cumulative update. Thank you for your answer. PavolSolved175Views0likes2CommentsChange the timezone for date/time - Arizona
Hello, I am in Arizona with no daylight saving. The SQL database I am pulling date/time codes has nightmarish Epoch (INT) fields for the date/time fields and it's in Eastern Time Zone. I figured out how to convert the code to date / time. However, HOW do I change the Eastern Time ZONE to either Pacific (Spring/Summer) or Mountain (Fall/Winter)?? Unfortunately, there is no Arizona Time Zone for MS SQL. Convert(varchar,DATEADD(MILLISECOND, CAST(RIGHT(Completed_Date, 3) AS INT) - DATEDIFF(MILLISECOND,GETDATE(),GETUTCDATE()), DATEADD(SECOND, CAST(LEFT(Completed_Date, 10) AS INT), '1970-01-01')),22)as 'PBI Completed Date' Thank you!Solved492Views0likes16CommentsSQL Query
Hi All, I have 2 tables ConfigurationTable and Data table. I require combine value like below output Source tables: Target Output: Sql Scripts: CREATE TABLE CONFIGTABLE(Productcode VARCHAR(10), Linkedvalue VARCHAR(10)) INSERT INTO CONFIGTABLE VALUES ('A', 'PEN') ,('C', 'PENCIL') ,('B', 'BOOK') ,('M', 'MOUSE') CREATE TABLE DATATABLE (FIELDVALUE VARCHAR(50), ORDERID INT,NAME VARCHAR(20)) INSERT INTO DATATABLE VALUES ('321', 9, 'COMPUTER') ,('THIS PEN IS', 1, 'A') ,('Country', 5, 'BOOK') ,('Great village in a', 4, 'B') ,('MINE', 2, 'PEN')Solved110Views0likes2CommentsStrange behavior of MSSQL Listener name + port
Hello, everyone. We are running MSSQL 2022, we have 2 listener and port, said LSNA with port 1434, LSNB with port 1435. The connection is no problem. But strange is that it can also go into DB with LSNA,1435 and LSNB,1434 which do not exist, it will go to DB according to port but not listener+port. Anyone can give advise to me on this? Thank you very much in advance.Solved169Views0likes3CommentsTable
Hello everyone, I have a problem. Our products are dimension-dependent (width / height) and the prices are stored in a table [Costinformation]. The grid table is in the Pricetable column. Rows are separated with CRLF and the individual columns with Tab. Table [Costinformation] Mandant Code Text Category Pricetable 1 4711 Product Table 1 Window 1 4712 Product Table 2 Door Example Pricetable-Column W / H 100 200 300 400 100 10,00 20,00 30,00 40,00 200 20,00 30,00 40,00 50,00 300 30,00 40,00 50,00 60,00 400 40,00 50,00 60,00 70,00 Now it is so that there are always price adjustments. In 100% of cases, this is in percentage terms. This means that the prices in the grid table have to be extrapolated. I need a solution so that I no longer have to do this manually. Can it be done directly via an SQL statement? Example: Product Table 1 --> price + 5% Produkt Table 2 --> price + 3 % I hope it is understandable. My English is not so good. I can also provide an example table. Thank you very much for you help. Greetings from Germany CharlyStellaSolved311Views0likes10CommentsHow to add existing log files to a newly created filegroup ?
I have two log files which are on different drives A: \logfile1.ldf & B:\logfile2.ldf which are not part of a file group. I want to remove logfile2.ldf , but I am unable to remove it because it is not empty. I tried emptying it by shrinking , but because it is not part of the filegroup, it failed. When I tried to add the files to a newly created filegroup, using ALTER DATABASE ADD FILE( name= 'logfile1', filename='A:\logfile1.ldf') TO FILEGROUP LOGFILE I got an error message The logical file name "logfile1" is already in use. Choose a different name. So, how can I add the log files to filegroup 'LOGFILE'? Thank you.Solved131Views0likes3CommentsDifference SQL Server 2022 vs 2017 Bind table
Hi, I'm Beginner SQL Server Engineer. I got some Question to SQL Server 2022, 2017 Bind table. During SQL Server practice, I heard that the bind table does not know statistical information, so there should be no IO reduction due to the index, but in the 2022 version, it seems that the index in the bind table refers to statistical information. something change between 2017 and 2022 Bind table?Solved143Views0likes2CommentsFilestream error - File location cannot be opened
Trying to solve this error: The File location cannot be opened. Either access is not enabled or you do not have permissions for the same. when trying to open a File Table using "Explore FileTable Directory" This is a client's computer and these are the configurations I have checked: SQL Server v 2019 (installed cumulative update today) Filestream enabled in configuration manager. All 3 check boxes are checked. In SSMS, instance has: Filestream Access Level = "Full access enabled", Filestream Share Name: MSSQLSERVER DB properties Filestream Directory Name is specified (and exists), Filestream Non-Transacted Access = "Full" Logged into computer as an admin and into SSMS as sa. I can execute a select statement against a filetable but am unable to access via the "Explore FileTable Directory" option. What am I missing?Solved266Views0likes3Comments
Events
Recent Blogs
- We’re happy to announce that SQL Server 2025 Release Candidate 1 (RC1) now includes preview support for Red Hat Enterprise Linux (RHEL) 10, expanding our commitment to modern, secure, and flexible Li...Sep 17, 2025404Views1like0Comments
- English follows Japanese. こんにちは、 SQL Server サポート チームです。 今回は、SQL IaaS Agent 拡張機能と Azure 上の SQL 仮想マシン リソースについて解説します。 SQL Server IaaS Agent 拡張機能とは SQL Server IaaS Agent 拡張機能は、Azure Porta...Sep 17, 2025119Views2likes0Comments