177 questions with SQL Server Transact-SQL tags

Sort by: Updated
1 answer

Sql Server to Excel

Hi Trying to export data from sql server to a Table formated excel. But after the data insert the Format of excel not coming properly. I mean the odd and even rows with different color Thanks

SQL Server Transact-SQL
SQL Server Transact-SQL
SQL Server: A family of Microsoft relational database management and analysis systems for e-commerce, line-of-business, and data warehousing solutions.Transact-SQL: A Microsoft extension to the ANSI SQL language that includes procedural programming, local variables, and various support functions.
177 questions
asked 2025-05-01T10:49:51.06+00:00
SVA 116 Reputation points
answered 2025-05-02T05:44:35.3033333+00:00
Olaf Helper 46,631 Reputation points
1 answer

SQL Server Management Studio 18 - Maintenance Plan

I have setup SQL backups to run daily at midnight for 5 servers, all works fine except 1 server does not run/create backup files. No errors or logs just does not run and not sure why. Any suggestions? Thanks! David

SQL Server Transact-SQL
SQL Server Transact-SQL
SQL Server: A family of Microsoft relational database management and analysis systems for e-commerce, line-of-business, and data warehousing solutions.Transact-SQL: A Microsoft extension to the ANSI SQL language that includes procedural programming, local variables, and various support functions.
177 questions
asked 2025-05-01T12:56:03.21+00:00
Chun, David 0 Reputation points
answered 2025-05-02T05:42:54.2466667+00:00
Olaf Helper 46,631 Reputation points
0 answers

Copying all tables from one Azure Managed Instance database to another

What is the best method to copy all tables from DatabaseA to DatabaseB in an Azure Managed Instance, including all object-level permissions, triggers, views, and indexes? The Export/Import and SELECT * INTO methods are known not to retain object-level…

SQL Server Transact-SQL
SQL Server Transact-SQL
SQL Server: A family of Microsoft relational database management and analysis systems for e-commerce, line-of-business, and data warehousing solutions.Transact-SQL: A Microsoft extension to the ANSI SQL language that includes procedural programming, local variables, and various support functions.
177 questions
asked 2025-04-28T00:09:58.4133333+00:00
Vijay Kumar 2,036 Reputation points
commented 2025-04-28T02:55:05.0533333+00:00
Luke Murray 11,351 Reputation points MVP
1 answer

SQL Server Limitations that aren't Solved

I use Sql Server 2022. I'm running Select queries using hundreds of words, and I need to know, for each matching record, which words were found. After running the Select query, I now have to run hundreds of searches for each word in each record, and…

SQL Server Transact-SQL
SQL Server Transact-SQL
SQL Server: A family of Microsoft relational database management and analysis systems for e-commerce, line-of-business, and data warehousing solutions.Transact-SQL: A Microsoft extension to the ANSI SQL language that includes procedural programming, local variables, and various support functions.
177 questions
asked 2025-04-23T23:52:20.8133333+00:00
Central data 156 Reputation points
commented 2025-04-25T14:52:31.7966667+00:00
Dan Guzman 9,376 Reputation points
1 answer

Query related to length in CAST and Output clause

Hi Team, Could you please reply to below queries - Using CAST, I need to convert BigInt and Datetime2 values to Varchar. How could I be sure on the length that I need to use (in CAST) to convert these values to Varchar. I am using Update statement…

SQL Server Transact-SQL
SQL Server Transact-SQL
SQL Server: A family of Microsoft relational database management and analysis systems for e-commerce, line-of-business, and data warehousing solutions.Transact-SQL: A Microsoft extension to the ANSI SQL language that includes procedural programming, local variables, and various support functions.
177 questions
asked 2025-04-22T18:21:46.98+00:00
Salil Singh 40 Reputation points
answered 2025-04-24T06:20:32.56+00:00
Olaf Helper 46,631 Reputation points
1 answer

BCP OUT/IN, What is native format and its usage. I am planning to use BCP out/in to export & Import table data from source to target and would like to know which is the best option when my data contains special character inside it and also have some email

BCP native format when to use when not to use. Is there any alternative BCP utility to export and import data from source to target table

SQL Server Transact-SQL
SQL Server Transact-SQL
SQL Server: A family of Microsoft relational database management and analysis systems for e-commerce, line-of-business, and data warehousing solutions.Transact-SQL: A Microsoft extension to the ANSI SQL language that includes procedural programming, local variables, and various support functions.
177 questions
asked 2025-04-24T05:15:22.5166667+00:00
C, Manoharan (Cognizant) 40 Reputation points
answered 2025-04-24T06:12:34.9+00:00
Olaf Helper 46,631 Reputation points
0 answers

SSMS got corrupted user settings and now SQL Prompt is no longer working

Good morning, I access SSMS through VDI. Today when I tried to open SSMS I got a message that my user settings got corrupted and do I want to restore from some long path. I believe I answered yes on that question. The connect server dialog didn't have…

SQL Server Transact-SQL
SQL Server Transact-SQL
SQL Server: A family of Microsoft relational database management and analysis systems for e-commerce, line-of-business, and data warehousing solutions.Transact-SQL: A Microsoft extension to the ANSI SQL language that includes procedural programming, local variables, and various support functions.
177 questions
asked 2025-04-21T16:59:02.76+00:00
Naomi Nosonovsky 8,351 Reputation points
commented 2025-04-21T19:19:40.6433333+00:00
Naomi Nosonovsky 8,351 Reputation points
0 answers

com.azure.core.management.exception.ManagementException: Long running operation is Failed or Cancelled. Error

This is happening quite frequently now. When I am creating Elastic job agent I get com.azure.core.management.exception.ManagementException: Long running operation is Failed or Cancelled. Now this error is happening with every api call. I am using…

SQL Server Transact-SQL
SQL Server Transact-SQL
SQL Server: A family of Microsoft relational database management and analysis systems for e-commerce, line-of-business, and data warehousing solutions.Transact-SQL: A Microsoft extension to the ANSI SQL language that includes procedural programming, local variables, and various support functions.
177 questions
asked 2025-04-16T16:23:33.9733333+00:00
Ayush Shrivastava 0 Reputation points
commented 2025-04-16T17:08:54.8766667+00:00
Ayush Shrivastava 0 Reputation points
1 answer One of the answers was accepted by the question author.

Why are query executed first blocked by update executed later

There are sessions 1-4, and session 1 is update, which is used to block the environment needed for other sessions to form. Symptom 1: Sessions 2 and 4 are select and 3 are update. 1-2-3-4 is executed in sequence. Once session 1 is terminated, I expect…

SQL Server Transact-SQL
SQL Server Transact-SQL
SQL Server: A family of Microsoft relational database management and analysis systems for e-commerce, line-of-business, and data warehousing solutions.Transact-SQL: A Microsoft extension to the ANSI SQL language that includes procedural programming, local variables, and various support functions.
177 questions
asked 2025-04-10T07:52:14.9666667+00:00
博雄 胡 585 Reputation points
accepted 2025-04-15T02:01:39.9066667+00:00
博雄 胡 585 Reputation points
1 answer

External Activation and Microservices Question

Hello, I am working on a proof-of-concept for my company using SQL Server and Service Broker External Activation to send messages from a database to a console application (both .NET and .NET Framework). I successfully created the working POC on my local…

SQL Server Transact-SQL
SQL Server Transact-SQL
SQL Server: A family of Microsoft relational database management and analysis systems for e-commerce, line-of-business, and data warehousing solutions.Transact-SQL: A Microsoft extension to the ANSI SQL language that includes procedural programming, local variables, and various support functions.
177 questions
asked 2025-04-14T13:14:00.1866667+00:00
Dionizio, Andrew 0 Reputation points
answered 2025-04-14T22:04:20.45+00:00
Dan Guzman 9,376 Reputation points
0 answers

Applying Non clustered Index on a table with no clustered index

Hi Team, I am working on to improve the performance of a Stored Procedure in SQL Server Database. Table scan is happening on a table on which there is no primary key defined. Structure of table is as such that primary key could not be defined on the…

SQL Server Transact-SQL
SQL Server Transact-SQL
SQL Server: A family of Microsoft relational database management and analysis systems for e-commerce, line-of-business, and data warehousing solutions.Transact-SQL: A Microsoft extension to the ANSI SQL language that includes procedural programming, local variables, and various support functions.
177 questions
asked 2025-04-14T18:45:28.6866667+00:00
Salil Singh 40 Reputation points
edited a comment 2025-04-14T21:37:29.79+00:00
Dan Guzman 9,376 Reputation points
0 answers

Improving SP performance using Non Clustered Index.

Hi Team, I need to improve performance of a SP which is in a Database in SQL Server. 1.One of the Select query uses a Table, which is having clustered index on Column A. This table is joined with other tables on columns A,B and C(all are columns of same…

SQL Server Transact-SQL
SQL Server Transact-SQL
SQL Server: A family of Microsoft relational database management and analysis systems for e-commerce, line-of-business, and data warehousing solutions.Transact-SQL: A Microsoft extension to the ANSI SQL language that includes procedural programming, local variables, and various support functions.
177 questions
asked 2025-04-10T18:15:20.8+00:00
Salil Singh 40 Reputation points
edited the question 2025-04-13T06:20:59.26+00:00
Salil Singh 40 Reputation points
2 answers One of the answers was accepted by the question author.

SQL 2022 -- cte + insert doesn't work

Good day, I have the following simple SQL statement: DELETE FROM stg.stg_facets_solo; ;WITH cte AS ( SELECT * , COUNT(*) OVER (PARTITION BY f.taxid) AS cntNpi , COUNT(*) OVER (PARTITION BY f.npi ,…

SQL Server Transact-SQL
SQL Server Transact-SQL
SQL Server: A family of Microsoft relational database management and analysis systems for e-commerce, line-of-business, and data warehousing solutions.Transact-SQL: A Microsoft extension to the ANSI SQL language that includes procedural programming, local variables, and various support functions.
177 questions
asked 2025-04-11T16:46:56.2133333+00:00
Naomi Nosonovsky 8,351 Reputation points
accepted 2025-04-11T21:15:06.6+00:00
Naomi Nosonovsky 8,351 Reputation points
0 answers

How to fix connectivity timeout issue between azure function and azure sql server.

We are trying to connect to SQL database using azure function. We are facing a connectivity timeout issue. Below is the error message :- 4/7/2025, 4:10:22.220 PM An error occurred in updateDatabase: RequestError: Timeout: Request failed to complete in…

SQL Server Transact-SQL
SQL Server Transact-SQL
SQL Server: A family of Microsoft relational database management and analysis systems for e-commerce, line-of-business, and data warehousing solutions.Transact-SQL: A Microsoft extension to the ANSI SQL language that includes procedural programming, local variables, and various support functions.
177 questions
asked 2025-04-09T14:16:52.67+00:00
Prashant 0 Reputation points
2 answers One of the answers was accepted by the question author.

Changing Primary Keys for Existing Tables Containing Data

Hi, Running SQL Server 2008 R2 SP3. We are working on implementing some DDL changes with the goal of improving overall performance. Aside from indexing strategies we would like to change the data type of primary key columns from varchar to bigint. …

SQL Server Transact-SQL
SQL Server Transact-SQL
SQL Server: A family of Microsoft relational database management and analysis systems for e-commerce, line-of-business, and data warehousing solutions.Transact-SQL: A Microsoft extension to the ANSI SQL language that includes procedural programming, local variables, and various support functions.
177 questions
asked 2025-03-22T04:05:32.15+00:00
VDT-7677 161 Reputation points
commented 2025-04-06T00:06:19.4066667+00:00
Erland Sommarskog 120.3K Reputation points MVP
1 answer

SQL Server 2019 replace() function does NOT replace char(30) with empty string properly

I ran across a funny bug in SQLserver 2019, when trying to replace char(30) (ascii character 30) in a string, with an empty string (effectively removing the char30 from the string), the replace() function also strips all trailing spaces in the string.…

SQL Server Transact-SQL
SQL Server Transact-SQL
SQL Server: A family of Microsoft relational database management and analysis systems for e-commerce, line-of-business, and data warehousing solutions.Transact-SQL: A Microsoft extension to the ANSI SQL language that includes procedural programming, local variables, and various support functions.
177 questions
asked 2025-04-04T17:43:27.09+00:00
Benjamin Nunes 0 Reputation points
edited an answer 2025-04-04T18:05:45.3433333+00:00
Viorel 121.4K Reputation points
2 answers One of the answers was accepted by the question author.

Adding Conditional Not Null Constraint to Table

Hi, Running SQL Server 2008 R2. DDL below: CREATE TABLE [dbo].[Test] ( [TestID] [bigint] NOT NULL IDENTITY, [Column1] [varchar](50) NOT NULL, [Column2] [varchar](50) NULL, [Column3] [varchar](50) NULL, [Flag] [bit] NOT NULL, CONSTRAINT…

SQL Server Transact-SQL
SQL Server Transact-SQL
SQL Server: A family of Microsoft relational database management and analysis systems for e-commerce, line-of-business, and data warehousing solutions.Transact-SQL: A Microsoft extension to the ANSI SQL language that includes procedural programming, local variables, and various support functions.
177 questions
asked 2025-03-25T20:47:55.5866667+00:00
VDT-7677 161 Reputation points
accepted 2025-04-04T03:02:34.3566667+00:00
VDT-7677 161 Reputation points
1 answer

How to change identity column in Clustered Index from int to big int for a 42gb table

Re: How to change identity column in Clustered Index from int to big int for a 42gb table I have a 43 gb table, with 30 mil rows, that has a clustered index with three fields. the third field is an integer identity column - col3 - that is now at…

SQL Server Transact-SQL
SQL Server Transact-SQL
SQL Server: A family of Microsoft relational database management and analysis systems for e-commerce, line-of-business, and data warehousing solutions.Transact-SQL: A Microsoft extension to the ANSI SQL language that includes procedural programming, local variables, and various support functions.
177 questions
asked 2025-03-31T17:12:42.1433333+00:00
Grossnickle, Brenda 120 Reputation points
commented 2025-04-02T08:36:27.3866667+00:00
Peter_1985 2,731 Reputation points
0 answers

How to migrate the data from on-prem MS SQL server blob table (having structured and un-structured data) to AWS RDS using MS SQL Server

I have a table contains 7 columns. CREATE TABLE DEV.My_Files (    file_id INT IDENTITY(1,1) PRIMARY KEY,   -- Unique identifier for each file    filename NVARCHAR(255) NOT NULL,         -- Original file name    file_extension NVARCHAR(10) NOT NULL,    --…

SQL Server Transact-SQL
SQL Server Transact-SQL
SQL Server: A family of Microsoft relational database management and analysis systems for e-commerce, line-of-business, and data warehousing solutions.Transact-SQL: A Microsoft extension to the ANSI SQL language that includes procedural programming, local variables, and various support functions.
177 questions
asked 2025-04-01T16:23:15.97+00:00
C, Manoharan (Cognizant) 40 Reputation points
commented 2025-04-01T16:26:32.4666667+00:00
C, Manoharan (Cognizant) 40 Reputation points
3 answers

Access query giving errors I can't explain

I have a complex query (below)   INSERT INTO SCHEDULE ( SONo, CustomerID, CustomerName, OrigQty, BalDueQty, UpdatedOn, ReqDt, DueDt, PricePerLb, ActTotal, OrderDt, ShippingMethod, PONo, PartNoReqd ) _SELECT SOsWithoutMatchingSCHEDULE.SONo,…

SQL Server Transact-SQL
SQL Server Transact-SQL
SQL Server: A family of Microsoft relational database management and analysis systems for e-commerce, line-of-business, and data warehousing solutions.Transact-SQL: A Microsoft extension to the ANSI SQL language that includes procedural programming, local variables, and various support functions.
177 questions
asked 2025-03-28T21:48:57.7+00:00
Maxine Nietz 1 Reputation point
answered 2025-03-31T07:09:54.0133333+00:00
Olaf Helper 46,631 Reputation points