196 questions with SQL Server Transact-SQL tags

Sort by: Updated
0 answers

Execution of the stored procedure gives different result comparing with the direct execution

Hi everybody, I'm getting very puzzling results executing stored procedure vs executing subset of the code from that stored procedure directly. I have the following code to execute SP: DECLARE @RC INT DECLARE @inp_region_nbr TINYINT = 1 DECLARE @inp_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.
196 questions
asked 2025-06-13T22:28:35.3266667+00:00
Naomi Nosonovsky 8,431 Reputation points
commented 2025-06-14T02:43:39.66+00:00
Viorel 122.1K Reputation points
2 answers

Issue with SQL Azure Secure Enclave: LIKE Clause Failing with Error".

I am using Microsoft SQL Azure (RTM) - 12.0.2000.8 , where I configured the secure enclave with VBS where I am using keyvalut for creating column master key. All the operators are working fine except like. Able to insert, update with where clause. Tried…

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.
196 questions
asked 2025-06-05T09:44:00.5466667+00:00
Ashish Singhal 0 Reputation points
commented 2025-06-09T21:09:32.73+00:00
Erland Sommarskog 121.3K Reputation points MVP Volunteer Moderator
2 answers

Using IsNull with different data types in SQL SERVER

Hi Team, I am working on on premises SQL Server. I have a requirement where I need to apply left outer join between 2 tables and use IsNull to show default data when columns are having null. Under ISNULL, if a column is null what shall i put for below…

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.
196 questions
asked 2025-06-06T18:06:46.15+00:00
Salil Singh 60 Reputation points
answered 2025-06-09T17:55:33.42+00:00
SUMIT RAY 0 Reputation points
1 answer One of the answers was accepted by the question author.

Regarding the stability of the execution plan generation

My English is not good, so I use a translator to communicate. Please excuse me if it's not accurate I'm optimizing an sql,I created a few indexes, and the cost exceeded the parallel threshold, and it reported that the optimization was prematurely…

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.
196 questions
asked 2025-06-06T06:58:03.05+00:00
博雄 胡 685 Reputation points
accepted 2025-06-09T03:33:17.3766667+00:00
博雄 胡 685 Reputation points
1 answer

SQL Linked Server Connection to Oracle

I have a linked server connection between my SQL server and remote Oracle server. I can query the Oracle server from SQL without issue. I need to insert data from SQL into Oracle. The problem is the table names in SQL are different than Oracle. I tried…

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.
196 questions
asked 2025-06-04T20:41:16.1066667+00:00
rr-4098 2,026 Reputation points
commented 2025-06-07T18:41:01.6733333+00:00
rr-4098 2,026 Reputation points
2 answers

Inquiry About Extended Stored Procedures

Hi Team, I hope you're doing well. I would appreciate it if you could help me understand the following: What is an Extended Stored Procedure in SQL Server? Why did Microsoft deprecate Extended Stored Procedures? A brief explanation would be greatly…

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.
196 questions
asked 2025-06-06T13:56:55.6933333+00:00
Abhishek Modi (amodi) 0 Reputation points
answered 2025-06-06T15:35:23.8766667+00:00
Erland Sommarskog 121.3K Reputation points MVP Volunteer Moderator
1 answer

Contains/Containstable and search in Like mode

I have indexed the "Contenido" field in Full Text. Searching with CONTAINS/CONTAINSTABLE in Like mode yields no matches when using words that contain the text "ous" (house). If I remove the asterisks and I write 'house', the text is…

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.
196 questions
asked 2025-06-03T02:01:30.92+00:00
Central data 156 Reputation points
answered 2025-06-03T05:55:55.5466667+00:00
Olaf Helper 47,416 Reputation points
5 answers

Enable parallelism for TSQL scalar UDFs involving CLR function call in SQL Server

We are working on a UDF solution for MSSQL Server. Currently we have scalar TSQL UDFs which calls CLR functions. CLR functions (written in C#) further calls C functions present in a DLL file which is imported by C# layer using DLLImport. Also due to some…

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.
196 questions
asked 2025-05-30T05:25:49.0966667+00:00
Rakesh Kumar 0 Reputation points
answered 2025-05-30T19:48:51.6266667+00:00
Erland Sommarskog 121.3K Reputation points MVP Volunteer Moderator
1 answer

SQLServerBulkCSVFileRecord java and quotes problem

i can't laod using SQLServerBulkCSVFileRecord (ver 12.10) a file like this: xxx;yyyy;test"test;zzzz simple file with 1 simple quote in nvarchar column, give error "com.microsoft.sqlserver.jdbc.SQLServerException: Unable to retrieve data from…

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.
196 questions
asked 2025-05-23T14:21:07.0933333+00:00
STELMACH Daniel Ext O-PL/Korpo 0 Reputation points
commented 2025-05-26T12:32:22.7633333+00:00
STELMACH Daniel Ext O-PL/Korpo 0 Reputation points
2 answers

Avoiding table locking while Update

Hi Team, I am working on a SQL Server Stored Procedure, where I need to update a column of a table in a no. of rows. This stored procedure will be called from a timer trigger Azure function, which will scale so that 2 function instances may call 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.
196 questions
asked 2025-05-21T18:29:31.7566667+00:00
Salil Singh 60 Reputation points
edited a comment 2025-05-22T00:07:29.6566667+00:00
Bruce (SqlWork.com) 77,476 Reputation points Volunteer Moderator
2 answers One of the answers was accepted by the question author.

Sql connectionstring "Old Password" attribute not working on OLE DB Driver for SQL Server - getting error "Invalid connection string attribute"

Sql connectionstring "Old Password" attribute not working on OLE DB Driver for SQL Server - getting error "Invalid connection string attribute" We have downloaded the OLE DB diver…

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.
196 questions
asked 2025-05-19T14:28:00.7066667+00:00
Alice Van Rensburg 20 Reputation points
accepted 2025-05-20T15:29:35.23+00:00
Alice Van Rensburg 20 Reputation points
2 answers

Error - FOR XML could not serialize the data for node 'NoName'

I am using FOR XML to concatenate varchar data. The data came from user input so it could have garbage characters. Getting the "Error - FOR XML Could Not Serialize the data for node NoName". Not really picky about what to do with the bad data,…

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.
196 questions
asked 2025-05-17T22:00:51.08+00:00
brenda grossnickle 206 Reputation points
edited an answer 2025-05-19T23:23:08.1+00:00
Yitzhak Khabinsky 26,571 Reputation points
2 answers One of the answers was accepted by the question author.

Table locked

Good day, My colleague was using Import/Export wizard and the package got stuck. He since killed SSMS, but the table got locked somehow. We're unable to truncate it or rename it. What can be done to unlock it? 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.
196 questions
asked 2025-05-15T18:02:46.8333333+00:00
Naomi Nosonovsky 8,431 Reputation points
answered 2025-05-15T21:05:44.94+00:00
Erland Sommarskog 121.3K Reputation points MVP Volunteer Moderator
1 answer One of the answers was accepted by the question author.

Restore Database from .MDF and .LDF files in Sql Server 2019

Hello, We have Sql Server 2019 and we need to restore the database using .MDF and .LDF file into existing database. We have received .MDF and .LDF file from another server which is also Sql 2019 and our current server which has already database which is…

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.
196 questions
asked 2025-05-13T20:26:29.48+00:00
pdsqsql 431 Reputation points
accepted 2025-05-15T15:45:57.1466667+00:00
pdsqsql 431 Reputation points
2 answers

What is the performance cost of using PIVOT in Microsoft SQL Server

I'm using PIVOT in my query, but it's resulting in high logical reads and performance degradation. Could you recommend a more optimal alternative approach.

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.
196 questions
asked 2025-05-14T15:07:42.86+00:00
RajeshKumar Tuta 0 Reputation points
answered 2025-05-14T20:39:00.74+00:00
Erland Sommarskog 121.3K Reputation points MVP Volunteer Moderator
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.
196 questions
asked 2025-05-09T13:15:11.4133333+00:00
Gil Robinson 0 Reputation points
commented 2025-05-12T06:29:48.6166667+00:00
Olaf Helper 47,416 Reputation points
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.
196 questions
asked 2025-05-09T14:14:17.4433333+00:00
Naomi Nosonovsky 8,431 Reputation points
commented 2025-05-11T19:33:08.9633333+00:00
Michael Taylor 59,986 Reputation points
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.
196 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 121.3K Reputation points MVP Volunteer 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.
196 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 121.3K Reputation points MVP Volunteer 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.
196 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