4,640 questions with Transact-SQL-related tags

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

Separating Name to First Name Last Name and Middle Name

Separating Name to First Name Last Name and Middle Name Have a Name Column holding a name with a format that varies case only two words exist in Name, I need to separate name into firstName and LastName and delete comma if exist case…

Transact-SQL
Transact-SQL
A Microsoft extension to the ANSI SQL language that includes procedural programming, local variables, and various support functions.
4,640 questions
asked 2022-03-19T08:51:25.15+00:00
Debilon 431 Reputation points
commented 2024-10-16T08:25:23.83+00:00
Morten Steensgaard 0 Reputation points
2 answers

How to get the non null row before the row with null value

Hi I want to see the non null row before the row with NULL value in the result set. I have data in below in format I want to see ID 2 row in the result set like below Help with this would be appreciated.

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,855 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.
98 questions
Transact-SQL
Transact-SQL
A Microsoft extension to the ANSI SQL language that includes procedural programming, local variables, and various support functions.
4,640 questions
asked 2024-10-14T19:48:43.02+00:00
Learner DAX 41 Reputation points
commented 2024-10-15T18:08:31.11+00:00
Erland Sommarskog 111.7K Reputation points MVP
3 answers

Msg 22050, Level 16, State 1, Line 0 Failed to initialize sqlcmd library with error number -2147467259.

DECLARE @RowId NVARCHAR(255) DECLARE @Query NVARCHAR(MAX) DECLARE @Header NVARCHAR(MAX) SET @RowId = '[sep=,' + CHAR(13) + CHAR(10) + 'RowId]' SET @Query = 'set nocount on; SELECT ROW_NUMBER() OVER (ORDER BY PDTMO.MONo DESC, PDTWF.CreateDate ASC) AS ' +…

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,855 questions
Transact-SQL
Transact-SQL
A Microsoft extension to the ANSI SQL language that includes procedural programming, local variables, and various support functions.
4,640 questions
asked 2024-06-28T05:37:28.5766667+00:00
Elson Wong 5 Reputation points
commented 2024-10-14T12:53:37.06+00:00
itspetro 0 Reputation points
2 answers

Use of Unique Index in TSQL

In TSQL what is the significance of having Unique constraints with Not Enforced enabled? Even after creating this I am able to insert duplicates within the table…

Azure Synapse Analytics
Azure Synapse Analytics
An Azure analytics service that brings together data integration, enterprise data warehousing, and big data analytics. Previously known as Azure SQL Data Warehouse.
4,932 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,855 questions
Transact-SQL
Transact-SQL
A Microsoft extension to the ANSI SQL language that includes procedural programming, local variables, and various support functions.
4,640 questions
asked 2024-10-10T07:16:10.43+00:00
SRIVASTAV, SOMYA 0 Reputation points
answered 2024-10-11T02:25:39.1866667+00:00
LiHongMSFT-4306 27,101 Reputation points
1 answer

Getting last modified SQL Database

Hi expert, we've already know how to get last modified data on specific table with SQL Trigger but how do we getting last modified Database either modified data(DML) or modified table\view (DDL) inside? does anyone have query for this? great thanks…

Transact-SQL
Transact-SQL
A Microsoft extension to the ANSI SQL language that includes procedural programming, local variables, and various support functions.
4,640 questions
asked 2024-10-09T09:44:44.87+00:00
UrBel 160 Reputation points
commented 2024-10-10T20:11:25.1066667+00:00
Erland Sommarskog 111.7K Reputation points MVP
7 answers One of the answers was accepted by the question author.

Microsoft SQL Server Studio - Dark Mode

Is there any official method to use Microsoft SQL Server Management Studio Studio with Dark Mode?

Azure SQL Database
Visual Studio
Visual Studio
A family of Microsoft suites of integrated development tools for building applications for Windows, the web and mobile devices.
5,137 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,855 questions
Transact-SQL
Transact-SQL
A Microsoft extension to the ANSI SQL language that includes procedural programming, local variables, and various support functions.
4,640 questions
asked 2023-12-19T13:11:52.4966667+00:00
Kıvanç ÖZDEMİR 130 Reputation points
commented 2024-10-09T10:08:35.4633333+00:00
Pedro Valente 5 Reputation points
1 answer

How to get a date of day in current week

Hi, I have table that stores configurations like In my sql code, I need to take currentDateTime and get current week date for Execution Day which is Wednesday. So, for this week, it will be 10-02-2024. Get following week wednesday date. Here it…

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,855 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.
98 questions
Transact-SQL
Transact-SQL
A Microsoft extension to the ANSI SQL language that includes procedural programming, local variables, and various support functions.
4,640 questions
asked 2024-10-02T17:24:40.53+00:00
Spunny 326 Reputation points
commented 2024-10-07T08:30:06.45+00:00
LiHongMSFT-4306 27,101 Reputation points
1 answer

Pivot query result (column name will change)

Hi there, Have been working on a huge database task and one part of it is the below. How do i pivot this 1 row with dynamic columns (column names will change) Query: select top 1 * from INFORMATION_SCHEMA.columns Output should be ColumnName |…

Azure SQL Database
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,855 questions
Transact-SQL
Transact-SQL
A Microsoft extension to the ANSI SQL language that includes procedural programming, local variables, and various support functions.
4,640 questions
asked 2024-10-02T23:08:15.1166667+00:00
RJ 166 Reputation points
commented 2024-10-07T08:11:39.2033333+00:00
LiHongMSFT-4306 27,101 Reputation points
0 answers

How to fix Couldn't remove the user xx from database xx from the external libraries folder, error: 0x80070003

Hi Team, One of my client machine I can see lot of error message like " Couldn't remove the user XX from database XX from the external libraries folder, error: 0x80070003 Can you please suggest what is the issue and fix for it. SQL server 2019…

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,855 questions
Transact-SQL
Transact-SQL
A Microsoft extension to the ANSI SQL language that includes procedural programming, local variables, and various support functions.
4,640 questions
asked 2024-10-04T12:38:59.1866667+00:00
Uday Paleti 20 Reputation points
commented 2024-10-07T03:25:11.44+00:00
LiHongMSFT-4306 27,101 Reputation points
3 answers

Excluding SLA CLock Time (Hold status) using PL/Sql Query and make MTTR

Hi, I have a query where I require to exclude "Hold Status" time b/w open to acknowledge status. So, support I have ticket '9607' and it is in the Open Status(INIT) and assigned. While selecting open to Hold and hold to open and then…

Transact-SQL
Transact-SQL
A Microsoft extension to the ANSI SQL language that includes procedural programming, local variables, and various support functions.
4,640 questions
asked 2022-07-05T14:50:53.463+00:00
Mohit Trehan 1 Reputation point
edited an answer 2024-10-06T20:09:40.64+00:00
Erland Sommarskog 111.7K Reputation points MVP
2 answers One of the answers was accepted by the question author.

Getting the number of days before a status change

How do I get the number of days between 2 dates before a status change. There are times a status could flip back in the the future. Original table To the following

Transact-SQL
Transact-SQL
A Microsoft extension to the ANSI SQL language that includes procedural programming, local variables, and various support functions.
4,640 questions
asked 2021-09-20T15:35:02.997+00:00
ojmp2001 ojmp2001 121 Reputation points
answered 2024-10-06T19:26:55.55+00:00
Peter Jonson 0 Reputation points
3 answers

What is the best choice for this scenario - CTE or View

Hello Team, I have a scenario where in the source data is in an Azure SQL DB. The data in the source is stored in the form of snapshots. For Ex:- Day1 - 500K Records, Day2 - 510K Records - Day3 - 520K Records (Total - 1.53M records). All the tables the…

Azure SQL Database
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,855 questions
Transact-SQL
Transact-SQL
A Microsoft extension to the ANSI SQL language that includes procedural programming, local variables, and various support functions.
4,640 questions
asked 2024-02-07T11:11:16.49+00:00
Nagesh CL 646 Reputation points
edited an answer 2024-10-02T22:22:32.6966667+00:00
Raja S 0 Reputation points
1 answer One of the answers was accepted by the question author.

Max value of each column in a table

Hi there, I have 500+ Azure SQL tables with total of 25000+ columns. Most of the tables have varchar (max), or nvarchar(max) but to contain a value which could only be 3 , 5 or 20 characters long. --for characters select max(**len(**columnname)) from…

Azure SQL Database
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,855 questions
Transact-SQL
Transact-SQL
A Microsoft extension to the ANSI SQL language that includes procedural programming, local variables, and various support functions.
4,640 questions
asked 2024-09-30T20:57:09.8933333+00:00
RJ 166 Reputation points
accepted 2024-10-01T23:00:39.44+00:00
RJ 166 Reputation points
1 answer One of the answers was accepted by the question author.

better query for select results based on date.

What is the best way to write this code to get the date results? I have the time throughout the day in the datetime field. SELECT * FROM Reconciliation.Documents D Inner Join Reconciliation.DocumentsTransaction T ON D.DocumentPKey = T.DocumentPKey WHERE…

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,855 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.
98 questions
Transact-SQL
Transact-SQL
A Microsoft extension to the ANSI SQL language that includes procedural programming, local variables, and various support functions.
4,640 questions
asked 2024-09-30T19:03:37.35+00:00
Jonathan Brotto 420 Reputation points
accepted 2024-10-01T14:47:10.7333333+00:00
Jonathan Brotto 420 Reputation points
3 answers

How to swap two rows in sql server

say ex: Id name 1 a 2 b 3 c 4 d 5 e 6 f i want output like: Id name 1 b 2 a 3 d 4 c 5 f 6 e Please help me how to write a SQL query

Azure SQL Database
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,855 questions
Transact-SQL
Transact-SQL
A Microsoft extension to the ANSI SQL language that includes procedural programming, local variables, and various support functions.
4,640 questions
asked 2021-09-28T13:27:36.797+00:00
Madhan Chimmili 7 Reputation points
answered 2024-09-29T04:36:33.8466667+00:00
Raja ❤️ 0 Reputation points
0 answers

How to get a CSV file from a T-SQL in SQL Agent

I am using SQL agent to schedule a task. This task is the execution of a script that performs a query to several databases and concatenates the output. I have managed to obtain a file but not a CSV file, that is, I cannot obtain a file separating the…

Transact-SQL
Transact-SQL
A Microsoft extension to the ANSI SQL language that includes procedural programming, local variables, and various support functions.
4,640 questions
asked 2024-09-26T13:24:49.4666667+00:00
LUIXANY COLISEE 0 Reputation points
commented 2024-09-26T21:40:12.4766667+00:00
Erland Sommarskog 111.7K Reputation points MVP
2 answers One of the answers was accepted by the question author.

Remove last 3 charecters in column

Hi, I need to remove three characters(.00) in below table result: 111111111 without (last three characters i.e .00) chr1111111111.0011111111.0011111111.001111111111.001111111.00111111.0011111111.001111.001111111.00

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,855 questions
Transact-SQL
Transact-SQL
A Microsoft extension to the ANSI SQL language that includes procedural programming, local variables, and various support functions.
4,640 questions
asked 2024-09-25T07:54:04.8233333+00:00
mrrobottelg 60 Reputation points
commented 2024-09-26T09:54:56.0033333+00:00
mrrobottelg 60 Reputation points
2 answers One of the answers was accepted by the question author.

Update statement

How to convert query into update statement... Unable to do it select rt.outstandingamount,rt.outstandingamount * TT_USD.RateMultiplier,ENTITY,FromCurrencyKeyFK,ConversionCurrencyKey,RateMultiplier from deltalake.FactARReceiptDetail RT LEFT outer JOIN…

Azure SQL Database
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,855 questions
Transact-SQL
Transact-SQL
A Microsoft extension to the ANSI SQL language that includes procedural programming, local variables, and various support functions.
4,640 questions
asked 2024-09-21T20:07:21.3333333+00:00
Vineet S 930 Reputation points
accepted 2024-09-26T02:32:25.3633333+00:00
Vineet S 930 Reputation points
0 answers

Like to review records incorrectly entered in the database

We have a database where we enter a record with a number with an alphanumeric suffix. But the software entered it incorrectly due to an algorithm issue which we are trying to fix now but past transactions need to be fixed in the database. If I know the…

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,855 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.
98 questions
Transact-SQL
Transact-SQL
A Microsoft extension to the ANSI SQL language that includes procedural programming, local variables, and various support functions.
4,640 questions
asked 2024-09-24T16:38:23.5633333+00:00
Jonathan Brotto 420 Reputation points
commented 2024-09-25T21:56:13.35+00:00
Erland Sommarskog 111.7K Reputation points MVP
1 answer

date function in Sql

I have a timestamp where I want to query only based on the date and exclude time.

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,855 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.
98 questions
Transact-SQL
Transact-SQL
A Microsoft extension to the ANSI SQL language that includes procedural programming, local variables, and various support functions.
4,640 questions
asked 2024-09-24T18:11:46.69+00:00
Jonathan Brotto 420 Reputation points
commented 2024-09-25T01:20:51.7166667+00:00
LiHongMSFT-4306 27,101 Reputation points