181 questions with SQL Server Transact-SQL tags

Sort by: Updated
2 answers One of the answers was accepted by the question author.

How to script views by a pattern

Hi, I'm wondering if there is a simple way to script views definitions by some pattern, e.g. views in a particular schema and named using 'ndb' in the name? Thanks in advance.

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.
181 questions
asked 2025-05-09T14:14:17.4433333+00:00
Naomi Nosonovsky 8,351 Reputation points
commented 2025-05-09T23:53:16.44+00:00
Michael Taylor 58,866 Reputation points
2 answers

Can a column name used as part of a CTE be used in the SELECT query that creates the CTE?

When converting a SQL script from SQL Anywhere to SQL Server, my code generated an error for the following CTE code sample; the error says that the column name used in the ROW_NUMBER function is invalid. Any suggestions on how to fix this would be…

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.
181 questions
asked 2025-05-09T13:15:11.4133333+00:00
Gil Robinson 0 Reputation points
answered 2025-05-09T20:39:36.6966667+00:00
Erland Sommarskog 120.4K Reputation points MVP Moderator
1 answer

Query hang on single user database

We created a new 24 vcore SQL Azure instance and are getting hangs for 81 minutes with no timeouts on an update which previous took seconds. There is only one user and no blocking session SELECT s.login_name, DB_NAME(r.database_id) AS…

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.
181 questions
asked 2025-05-09T20:07:38.4233333+00:00
Matt Esterly 0 Reputation points
answered 2025-05-09T20:28:07.7+00:00
Erland Sommarskog 120.4K Reputation points MVP Moderator
3 answers One of the answers was accepted by the question author.

Cannot insert Bassa Vah characters into SQL Server database

I am using SQL Server and Visual Studio 2022 for a language database, but I am unable to insert characters from this page for the Bassa Vah script (https://scriptsource.org/cms/scripts/page.php?item_id=character_list&key=16AD0). I tried NVARCHAR…

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.
181 questions
asked 2025-05-08T02:15:30.54+00:00
Dukaw LiberiaInfo 20 Reputation points
commented 2025-05-09T09:31:54.4133333+00:00
Erland Sommarskog 120.4K Reputation points MVP Moderator
2 answers

Getting a Table Column value in Catch section while using Output clause for Update Statement

Hi Team, I am working on a SQL Server Stored Procedure which uses Output clause for Update Statement. Table getting updated is having a column name as ID. I need to put Try Catch in this SP and make sure that row which has errored, I am able to get 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.
181 questions
asked 2025-05-08T18:13:11.07+00:00
Salil Singh 60 Reputation points
edited an answer 2025-05-09T07:48:14.54+00:00
Naveen Kumar M 175 Reputation points
1 answer One of the answers was accepted by the question author.

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.
181 questions
asked 2025-04-22T18:21:46.98+00:00
Salil Singh 60 Reputation points
accepted 2025-05-08T17:49:10.58+00:00
Salil Singh 60 Reputation points
1 answer

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.
181 questions
asked 2025-04-28T00:09:58.4133333+00:00
Vijay Kumar 2,036 Reputation points
answered 2025-05-08T15:32:57.71+00:00
Naveen Kumar M 175 Reputation points
1 answer One of the answers was accepted by the question author.

Is Select x like %(% as newname possible in a query

I have the following query that produces correct results however since UnRegMale or UnRegFemale may be bracketed in which case I need to select that field as '' in the query. Bracketed names in the table are not competitors but support persons whose…

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.
181 questions
asked 2025-05-07T08:39:39.28+00:00
Hugh Self Taught 101 Reputation points
commented 2025-05-07T09:16:40.34+00:00
Hugh Self Taught 101 Reputation points
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.
181 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,641 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.
181 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,641 Reputation points
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.
181 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,391 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.
181 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,641 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.
181 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.
181 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.
181 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.
181 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,391 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.
181 questions
asked 2025-04-14T18:45:28.6866667+00:00
Salil Singh 60 Reputation points
edited a comment 2025-04-14T21:37:29.79+00:00
Dan Guzman 9,391 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.
181 questions
asked 2025-04-10T18:15:20.8+00:00
Salil Singh 60 Reputation points
edited the question 2025-04-13T06:20:59.26+00:00
Salil Singh 60 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.
181 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.
181 questions
asked 2025-04-09T14:16:52.67+00:00
Prashant 0 Reputation points