278 questions with SQL Server | SQL Server Transact-SQL tags

Sort by: Updated
2 answers

Stored Procedure running longer hours

Hello, I am facing currently issue as stored procedure running very longer hours although my DB is not that big means around 20 GB. We are also running OLA's maintenance solution for Update Stats Daily and Index maintenance weekly basis. Stored procedure…

SQL Server | SQL Server Transact-SQL
asked 2026-03-21T16:55:37.63+00:00
pdsqsql 436 Reputation points
commented 2026-03-29T00:37:49.7266667+00:00
Erland Sommarskog 133.6K Reputation points MVP Volunteer Moderator
2 answers

Sequel server licensing

My distributer is telling me that SQL Server Standard 2022 - 2 Core License Pack - 3 yearSQL Server Standard 2022 - 2 Core License Pack - 3 year billed annually is a perpetual license? I have query with this as it has a termed subscription time?…

SQL Server | SQL Server Transact-SQL
asked 2026-03-02T03:07:55.3166667+00:00
Esther Cleave 0 Reputation points
commented 2026-03-26T06:42:57.05+00:00
Akhil Gajavelly 1,570 Reputation points Microsoft External Staff Moderator
1 answer

Implementing User-Defined Sort via Trigger

Hi, Running SQL Server 2008 R2. We have a requirement to implement an arbitrary sort for a table using a numeric sort column. DDL and DML below: CREATE TABLE [dbo].[Test] ( [TestID] [bigint] IDENTITY(1,1) NOT NULL, …

SQL Server | SQL Server Transact-SQL
asked 2025-10-20T12:47:59.12+00:00
VDT-7677 171 Reputation points
commented 2026-03-24T04:57:21.8133333+00:00
Akhil Gajavelly 1,570 Reputation points Microsoft External Staff Moderator
1 answer

Identity Column jumps massively from 168712 to 9999993

I have table with identity column id. There was massive jump from id 168712 to 9999993. It has happened twice in different servers. Its not identity cache/transaction rollback/manual insert/ reseed. Why its happening. Please guide me on this.

SQL Server | SQL Server Transact-SQL
asked 2025-10-17T16:06:46.38+00:00
Perumal, Gowthami 5 Reputation points
commented 2026-03-24T04:43:06.38+00:00
Akhil Gajavelly 1,570 Reputation points Microsoft External Staff Moderator
2 answers

how to fix error 1205 on mssql 2022

Riscontro vari errori 1205 nei log e dopo alcuni di questi, si verifica l'errore 824

SQL Server | SQL Server Transact-SQL
asked 2026-02-23T19:02:26.01+00:00
Luca Benedetto 20 Reputation points
recommended 2026-03-20T12:23:16.2066667+00:00
Madhavi Taniparthi 0 Reputation points Microsoft External Staff Moderator
2 answers One of the answers was accepted by the question author.

SQL query across linked servers

Hi All, I have a number of linked servers. In each server I have the same table Q_TESTS. I would like to run t-sql script across all the servers, select * from Q_TESTS where Act = 1 How can I achieve this? Kindly advise Many thanks

SQL Server | SQL Server Transact-SQL
asked 2026-03-17T09:13:39.18+00:00
Rontech10111 221 Reputation points
accepted 2026-03-18T06:40:08.0366667+00:00
Rontech10111 221 Reputation points
3 answers

Copying a 32-Million Row Table From Production Server to Test Server

So we believe we're having tempdb issues with a very wide table that has 32-Million Rows on it. There is no Primary Clustered Index, No Indexes defined on it at all. We have tried an INSERT SELECT going across a Linked Server to our Test Server to copy…

SQL Server | SQL Server Transact-SQL
asked 2026-03-13T19:43:14.18+00:00
Bobby P 271 Reputation points
edited a comment 2026-03-15T11:06:06.3666667+00:00
Erland Sommarskog 133.6K Reputation points MVP Volunteer Moderator
1 answer One of the answers was accepted by the question author.

Best, Most Efficient DATETIME filtering

I have seen many discussions regarding doing filtering against a DATETIME Data Type. Some suggest to use a true DATTETIME format. WHERE <DATETIME_Column_Name> >= '2026-02-17 00:00:00.000' Others suggest to use just a quoted Date... WHERE…

SQL Server | SQL Server Transact-SQL
asked 2026-03-13T14:16:26.6766667+00:00
Bobby P 271 Reputation points
accepted 2026-03-13T14:23:05.8766667+00:00
Bobby P 271 Reputation points
2 answers One of the answers was accepted by the question author.

How to create initial full backup followed by transaction logs daily?

This is related to work. I have been sending out a full-back up of a database in BAK file format (using SQL Server 2022) for a client, but now the client is asking for an initial full backup followed by transaction logs daily. How do I go about doing it…

SQL Server | SQL Server Transact-SQL
asked 2026-01-30T18:06:58.63+00:00
Justin Doh 980 Reputation points
commented 2026-03-12T22:01:04.1566667+00:00
Erland Sommarskog 133.6K Reputation points MVP Volunteer Moderator
2 answers

What is SQL error ID 8179 and how to fix it?

The customer often found NAV Server error at Event Viewer (Application log), Event ID 216, MicrosoftDynamicsNavServer$MBKNAV.  It was NavSqlException, SQL error ID 8179 (“Could not find prepared statement with handle …”).  This issue often occurs when…

SQL Server | SQL Server Transact-SQL
asked 2026-02-18T02:58:30.2366667+00:00
Chirayu Traihirun 0 Reputation points
commented 2026-03-11T05:08:00.9266667+00:00
Akhil Gajavelly 1,570 Reputation points Microsoft External Staff Moderator
1 answer One of the answers was accepted by the question author.

Best and most efficient way to convert a VARCHAR(10) to a Date for filtering

We have a "Blob" Table with a Date and a Data Type of VARCHAR(10). What is the best and most efficient way to convert that to a Date so that we can look back and filter based on the last 3-years? Thanks in advance for your review and am hopeful…

SQL Server | SQL Server Transact-SQL
asked 2026-03-09T16:08:28.7233333+00:00
Bobby P 271 Reputation points
accepted 2026-03-09T19:37:59.6+00:00
Bobby P 271 Reputation points
2 answers One of the answers was accepted by the question author.

Point in time restore after initial backup

Hello, I have a specific question to which i coulnd't really find an exact answer. I have a scenario in which let's say I have an initial full backup(no backups present before that) that for some reason is slow and takes let's say 5 hours, starting at…

SQL Server | SQL Server Transact-SQL
asked 2026-03-06T12:46:29.77+00:00
Duygu Hasan 20 Reputation points
commented 2026-03-09T08:19:04.81+00:00
Duygu Hasan 20 Reputation points
1 answer One of the answers was accepted by the question author.

SSMS does not recognize data table

SSMS does not recognize data table....how do I fix this? See images below.

SQL Server | SQL Server Transact-SQL
asked 2026-03-03T16:33:32.1966667+00:00
SuperCoder 336 Reputation points
commented 2026-03-03T16:47:38.3066667+00:00
SuperCoder 336 Reputation points
3 answers

unable install sql on on pc due to power shell error

unable install sql on on pc due to power shell error

SQL Server | SQL Server Transact-SQL
asked 2026-02-08T08:45:29.2966667+00:00
pravin bhingardive 0 Reputation points
recommended 2026-03-02T18:05:09.6366667+00:00
Madhavi Taniparthi 0 Reputation points Microsoft External Staff Moderator
2 answers One of the answers was accepted by the question author.

A Scalar UDF works consistently in SQL Server 2017, fails sporadically under 2019 and 2022.

You can try this at home! I use this udf to capture the number of cores available when my stored procedure runs in cloud. But, since I develop against my local on-prem database, I coded it to return a -1 when it's not running in the cloud. Here's the…

SQL Server | SQL Server Transact-SQL
asked 2026-02-23T22:52:16.3333333+00:00
Steve Grimes 20 Reputation points
commented 2026-02-24T14:55:33.2633333+00:00
Steve Grimes 20 Reputation points
5 answers One of the answers was accepted by the question author.

Syntax error in the statement

Hi, I wrote the following query and trying to figure out the syntax error: incorrect syntax near WHERE. DECLARE @SQL NVARCHAR(MAX) SET @SQL = (SELECT 'SELECT COUNT(*) FROM rv.' + table_name, +','+ QUOTENAME((table_name) + ' as table_name ' FROM…

SQL Server | SQL Server Transact-SQL
asked 2026-02-17T18:25:30.1766667+00:00
Naomi Nosonovsky 8,906 Reputation points
answered 2026-02-19T21:44:00.48+00:00
Erland Sommarskog 133.6K Reputation points MVP Volunteer Moderator
2 answers One of the answers was accepted by the question author.

How can I create TRN file to capture only difference daily (between TRN files)?

I am trying to understand how Transaction Log works. This question is related to my previous post. My requirement is, instead of providing BAK file (because it is huge), I am trying to generate one TRN file daily for any change (insert, update or delete)…

SQL Server | SQL Server Transact-SQL
asked 2026-02-05T20:07:21.91+00:00
Justin Doh 980 Reputation points
accepted 2026-02-12T18:03:29.3766667+00:00
Justin Doh 980 Reputation points
2 answers

sqlcmd to backup on one server and write to another

I have a sql agent job that runs a CmdExec step on server 'Destination'. It executes a full backup on server 'Source' and needs to write the backup to server 'Destination'. This works perfectly when the server names are hard coded. However, both the…

SQL Server | SQL Server Transact-SQL
asked 2026-02-04T23:00:41.0833333+00:00
bukkybu 386 Reputation points
recommended 2026-02-05T22:40:12.2866667+00:00
Erland Sommarskog 133.6K Reputation points MVP Volunteer Moderator
3 answers One of the answers was accepted by the question author.

Dose SQL Server works on Snapdragon Arm Laptop

Dose SQL Server works on Snapdragon Arm based Laptop. if yes how to run on arm based Snapdragon Laptop

SQL Server | SQL Server Transact-SQL
asked 2026-01-18T07:52:19.76+00:00
Mudassir Ahmed 100 Reputation points
accepted 2026-02-02T10:00:00.6033333+00:00
Mudassir Ahmed 100 Reputation points
1 answer

SQL error -An expression of non-boolean type specified in a context where a condition is expected

Thanks in advance for any help folks can offer. I've been pulling my hair our all day yesterday trying to figure out how to fix this. I received the error below after I added 3 new lines (line 60, 61 and 62). The original code without these 3 new lines…

SQL Server | SQL Server Transact-SQL
asked 2026-01-26T18:29:09.99+00:00
DW 0 Reputation points
commented 2026-01-29T21:46:48.2633333+00:00
D Weeman 0 Reputation points