55 questions with SQL Server Transact-SQL tags

Sort by: Updated
0 answers

Upgrading SQL Server having multiple instances

Our SQL is of 2014 RTM. Planned to upgrade it to 2014 SP3 in the first place later to 2022. And our SQL Server do have extra 2 instances as being used for replication DBs. I saw rolling upgrade as solution to HA environment. But nowhere could I see…

SQL Server
SQL Server
A family of Microsoft relational database management and analysis systems for e-commerce, line-of-business, and data warehousing solutions.
13,035 questions
SQL Server Reporting Services
SQL Server Reporting Services
A SQL Server technology that supports the creation, management, and delivery of both traditional, paper-oriented reports and interactive, web-based reports.
2,849 questions
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.
55 questions
asked 2024-06-12T06:56:26.71+00:00
Radhai Krish 61 Reputation points
2 answers One of the answers was accepted by the question author.

Towards upgrading SQL 2014 to 2019

We are brim of making upgrading Windows Server as well as SQL Server. Currently we are having SQL 2014 RTM, Enterprise Edition in Windows Server 2012 R2 We purchased license for SQL 2022, Enterprise Edition and on process of purchasing license for…

Windows Server 2019
Windows Server 2019
A Microsoft server operating system that supports enterprise-level management updated to data storage.
3,537 questions
SQL Server
SQL Server
A family of Microsoft relational database management and analysis systems for e-commerce, line-of-business, and data warehousing solutions.
13,035 questions
Windows Server 2012
Windows Server 2012
A Microsoft server operating system that supports enterprise-level management, data storage, applications, and communications.
1,556 questions
Windows Server
Windows Server
A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.
12,394 questions
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.
55 questions
asked 2024-06-08T11:26:56.5266667+00:00
Radhai Krish 61 Reputation points
accepted 2024-06-10T04:15:20.7333333+00:00
Radhai Krish 61 Reputation points
1 answer One of the answers was accepted by the question author.

Set up valuable Indexes on a table

I have a really big transaction table, billions of rows, and I need some kinds of Indexes to make it useful. Right now there is a clustred columnstore index on the table, and a nonclustred on ID, but I guess I need some nonclustred to make the 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.
55 questions
asked 2024-05-31T14:45:31.69+00:00
Fredrik M 166 Reputation points
accepted 2024-06-07T08:09:41.8966667+00:00
Fredrik M 166 Reputation points
3 answers One of the answers was accepted by the question author.

SQL Server wrongly using Inner Join instead of Left join.

I am working on SQL Server version 2019 with compatibility mode = 150. There is a scenario where I am using two tables TableA & TableB. Where I have to pull records which are not present in TableB but present in TableA. So I have created a simulation…

SQL Server
SQL Server
A family of Microsoft relational database management and analysis systems for e-commerce, line-of-business, and data warehousing solutions.
13,035 questions
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.
55 questions
asked 2024-06-07T04:33:29.9166667+00:00
Vikrant Ashokrao More 20 Reputation points
accepted 2024-06-07T07:08:59.42+00:00
Vikrant Ashokrao More 20 Reputation points
3 answers

SQL Server Non Clustered Index CREATE taking forever to cancel

I ran a CREATE NON CLUSTERED INDEX command for 1.5 hours. Decided to cancel it because it was stopping other things running. The command has now been running for 22 hours. What is it doing that takes so long to roll back? The table is 2 billion rows and…

SQL Server
SQL Server
A family of Microsoft relational database management and analysis systems for e-commerce, line-of-business, and data warehousing solutions.
13,035 questions
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.
55 questions
asked 2024-05-23T00:03:03.8166667+00:00
Nick Ryan 221 Reputation points
commented 2024-05-29T21:20:39.37+00:00
Erland Sommarskog 103.1K Reputation points MVP
1 answer

delimited split gives null for some items

hi all, I am using a function to split a string into multiple rows. The function is available here: https://www.sqlservercentral.com/articles/tally-oh-an-improved-sql-8k-%e2%80%9ccsv-splitter%e2%80%9d-function What I am trying to figure out is how to…

SQL Server
SQL Server
A family of Microsoft relational database management and analysis systems for e-commerce, line-of-business, and data warehousing solutions.
13,035 questions
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.
55 questions
Transact-SQL
Transact-SQL
A Microsoft extension to the ANSI SQL language that includes procedural programming, local variables, and various support functions.
4,574 questions
asked 2024-05-29T13:43:14.27+00:00
elsvieta 346 Reputation points
commented 2024-05-29T15:01:51.0966667+00:00
elsvieta 346 Reputation points
1 answer

Why does impersonation (Execute as) work in a User database and not in the master database in Azure SQL DB?

Execute As User = 'User1' doesn't work in the Azure SQL DB master database. User1 account created in the master database and in a user database. Execute As User works in the user database and in the master database, receives the error: Msg 15517, Level…

Azure SQL Database
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.
55 questions
asked 2024-05-21T17:00:07.2233333+00:00
Jerimy Stanley 0 Reputation points
commented 2024-05-22T20:56:36.25+00:00
Erland Sommarskog 103.1K Reputation points MVP
2 answers One of the answers was accepted by the question author.

Help with SQL

Hi Experts, Need help in creating calculated columns as below. My Data: Expected Result of two calculated columns: Calculated Column 1 = Previous calculated value in Calculated Column 1 * Rate Calculated Column 2 = RecentMinRent * current…

SQL Server
SQL Server
A family of Microsoft relational database management and analysis systems for e-commerce, line-of-business, and data warehousing solutions.
13,035 questions
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.
55 questions
Transact-SQL
Transact-SQL
A Microsoft extension to the ANSI SQL language that includes procedural programming, local variables, and various support functions.
4,574 questions
asked 2024-05-11T17:16:52.7+00:00
Shyam Sreeramula 21 Reputation points
commented 2024-05-13T02:29:19.6766667+00:00
Shyam Sreeramula 21 Reputation points
0 answers

COALESCE and CONCAT Address Line 1 and Address Line 2 separated by a comma

We are trying to COALESCE and CONCAT Address Line 1 and Address Line 2 separated by a comma "," from potentially two data sources. So like...123 Main St., Apt. 101 The first part is easy enough... CONCAT ( COALESCE ( LTRIM (RTRIM…

SQL Server
SQL Server
A family of Microsoft relational database management and analysis systems for e-commerce, line-of-business, and data warehousing solutions.
13,035 questions
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.
55 questions
Transact-SQL
Transact-SQL
A Microsoft extension to the ANSI SQL language that includes procedural programming, local variables, and various support functions.
4,574 questions
asked 2024-05-09T18:55:45.0266667+00:00
Bobby P 221 Reputation points
commented 2024-05-10T01:28:42.8933333+00:00
LiHongMSFT-4306 24,266 Reputation points
1 answer

Parsing First, Last, Middle Initial and suffix from full name

I am trying to extract first last middle initial and suffix from a name field and there's no set pattern please see the pattern of the in my table LOPEZ ROQUE, CARMELINA ORTEGA, GISELLE A A RUSSELL JR, WILLIE C NUNEZ, LILIANA I have looked online 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.
55 questions
Transact-SQL
Transact-SQL
A Microsoft extension to the ANSI SQL language that includes procedural programming, local variables, and various support functions.
4,574 questions
asked 2024-04-01T01:59:34.55+00:00
Ali Ahad 111 Reputation points
answered 2024-05-10T00:59:34.6+00:00
Bruce (SqlWork.com) 59,016 Reputation points
2 answers One of the answers was accepted by the question author.

How can I resolve the "could not find server" error when using execute(@sql) at [linked_server] with a stored procedure?

I have created a stored procedure in SQL Server to execute a PL/SQL script to a linked Oracle server using either sp_executesql or execute(@sql). The former method works while the latter generates a "cannot find linked server" or…

SQL Server
SQL Server
A family of Microsoft relational database management and analysis systems for e-commerce, line-of-business, and data warehousing solutions.
13,035 questions
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.
55 questions
asked 2024-05-08T15:59:54.14+00:00
Timothy Dooling 25 Reputation points
commented 2024-05-08T23:10:31.9133333+00:00
Timothy Dooling 25 Reputation points
0 answers

When using execute(@sql) at [linked_server] I get "Could not find server" error

I have written the following stored procedure to execute a PL/SQL script to a linked Oracle server: ALTER PROCEDURE [dbo].[Oracle_s] ( @sql varchar(4000) ) AS BEGIN declare @result bit = 0; set nocount on; declare @temp nvarchar(4000) = 'SELECT *…

SQL Server
SQL Server
A family of Microsoft relational database management and analysis systems for e-commerce, line-of-business, and data warehousing solutions.
13,035 questions
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.
55 questions
asked 2024-05-08T15:24:55.69+00:00
Timothy Dooling 25 Reputation points
commented 2024-05-08T21:14:12.93+00:00
Erland Sommarskog 103.1K Reputation points MVP
2 answers

Text delimiter file

Hi, I have two tables: one for headers with 9 fields and another for lines with 6 fields. Both header and lines are highlited in yellow. I need to combine both the headers and lines using a UNION operation to display the result below. From the line…

SQL Server
SQL Server
A family of Microsoft relational database management and analysis systems for e-commerce, line-of-business, and data warehousing solutions.
13,035 questions
SQL Server Integration Services
SQL Server Integration Services
A Microsoft platform for building enterprise-level data integration and data transformations solutions.
2,479 questions
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.
55 questions
asked 2024-05-06T14:48:13.48+00:00
Vicki 46 Reputation points
answered 2024-05-07T02:18:28.6533333+00:00
LiHongMSFT-4306 24,266 Reputation points
1 answer

sql query where with condition

Hi, I have a query same but only one of the where clauses differ. If (@accountID = 100) Begin select field1, field2 FROM table1 left outer join table 2 where status = 'x' and ISNULL(accountid, @accountID) = @accountID END Else select field1,…

SQL Server
SQL Server
A family of Microsoft relational database management and analysis systems for e-commerce, line-of-business, and data warehousing solutions.
13,035 questions
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.
55 questions
Transact-SQL
Transact-SQL
A Microsoft extension to the ANSI SQL language that includes procedural programming, local variables, and various support functions.
4,574 questions
asked 2024-05-02T22:32:38.0266667+00:00
Spunny 326 Reputation points
edited the question 2024-05-03T01:35:39.6133333+00:00
LiHongMSFT-4306 24,266 Reputation points
1 answer One of the answers was accepted by the question author.

How to Calculate salary of employee

I am calculating salary using below query SELECT '29' as Total_Days,'28' as Present_Days, (14000 / 29) AS Per_Day, (14000 / 29) * 28 AS Total_Salary; But Total_Salary should be 14000 because Total_Days 29 and Present_Day 29

SQL Server
SQL Server
A family of Microsoft relational database management and analysis systems for e-commerce, line-of-business, and data warehousing solutions.
13,035 questions
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.
55 questions
asked 2024-04-27T06:08:58.23+00:00
Analyst_SQL 3,551 Reputation points
accepted 2024-04-28T11:39:25.0166667+00:00
Analyst_SQL 3,551 Reputation points
1 answer

Retrieve value from the row above

How can I retrieve the FinalBalance value from the previous row and add it to the Total value in the current row, to get the new FinalBalance value for each row? The table structure and desired outcome are shown in the image below. Each row's TransDate…

SQL Server
SQL Server
A family of Microsoft relational database management and analysis systems for e-commerce, line-of-business, and data warehousing solutions.
13,035 questions
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.
55 questions
asked 2024-04-15T21:16:50.3333333+00:00
Michael M.M. D'Angelo 176 Reputation points
commented 2024-04-23T06:45:53.98+00:00
LiHongMSFT-4306 24,266 Reputation points
4 answers

SQL Server optional parameter performance issue

Hello guys, I have an optional parameter in a SP e.g. @MyParam int = NULL When I check the param against NULL upfront I end up with TWO queries e.g. IF (@MyParam IS NULL) BEGIN SELECT ... END ELSE BEGIN SELECT ... END Otherwise if I check…

SQL Server
SQL Server
A family of Microsoft relational database management and analysis systems for e-commerce, line-of-business, and data warehousing solutions.
13,035 questions
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.
55 questions
Transact-SQL
Transact-SQL
A Microsoft extension to the ANSI SQL language that includes procedural programming, local variables, and various support functions.
4,574 questions
asked 2024-04-05T12:56:45.11+00:00
Kuler Master 266 Reputation points
commented 2024-04-23T06:19:14.9066667+00:00
LiHongMSFT-4306 24,266 Reputation points
2 answers One of the answers was accepted by the question author.

best approach to migrating a table from system to another

I have a test system where we update entries on a table for cross refence purpose and was wondering the best approach for this.

SQL Server
SQL Server
A family of Microsoft relational database management and analysis systems for e-commerce, line-of-business, and data warehousing solutions.
13,035 questions
SQL Server Migration Assistant
SQL Server Migration Assistant
A Microsoft tool designed to automate database migration to SQL Server from Access, DB2, MySQL, Oracle, and SAP ASE.
502 questions
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.
55 questions
Transact-SQL
Transact-SQL
A Microsoft extension to the ANSI SQL language that includes procedural programming, local variables, and various support functions.
4,574 questions
asked 2024-04-19T19:52:02.5533333+00:00
Jonathan Brotto 140 Reputation points
accepted 2024-04-22T13:09:20.73+00:00
Jonathan Brotto 140 Reputation points
2 answers

cleanup old transactional replication snapshot files

I have a transactional replication between a publisher and a subscriber where the subscriber also acts as the distributor. I am facing storage issues as old snapshot files are not being auto cleaned up after successful application via distributor. I…

SQL Server
SQL Server
A family of Microsoft relational database management and analysis systems for e-commerce, line-of-business, and data warehousing solutions.
13,035 questions
Windows Server
Windows Server
A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.
12,394 questions
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.
55 questions
asked 2024-04-18T17:46:01.6433333+00:00
Abimbola Adeniran 46 Reputation points
answered 2024-04-21T23:59:42.69+00:00
Abimbola Adeniran 46 Reputation points
1 answer One of the answers was accepted by the question author.

VB.NET SQL Connection and SQL Command Error BC3002

Hello, I'm in the process of converting VBA to VB.NET with SQL statements. One of the changes is utilizing the "ExecuteNonQuery". Since I'm still learning the syntax, I simply copied the VB.NET statements from a web-site. But I'm getting 2…

VB
VB
An object-oriented programming language developed by Microsoft that is implemented on the .NET Framework. Previously known as Visual Basic .NET.
2,620 questions
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.
55 questions
Transact-SQL
Transact-SQL
A Microsoft extension to the ANSI SQL language that includes procedural programming, local variables, and various support functions.
4,574 questions
asked 2024-04-16T16:02:09.4533333+00:00
Giacomo Raucci 321 Reputation points
commented 2024-04-19T00:41:22.3566667+00:00
Giacomo Raucci 321 Reputation points