4,591 questions with Transact-SQL-related tags

Sort by: Updated
3 answers

Training database PUBS

Dear friends, I'm looking for a description of the tables and fields of the Pubs training database. Can you help me please? Thank you very much, Anna

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,194 questions
Transact-SQL
Transact-SQL
A Microsoft extension to the ANSI SQL language that includes procedural programming, local variables, and various support functions.
4,591 questions
asked 2021-05-07T16:47:27.23+00:00
BIVS Databaze 1 Reputation point
answered 2024-07-04T12:13:44.9366667+00:00
Anthony Lesar 0 Reputation points
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.
4,820 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,194 questions
Transact-SQL
Transact-SQL
A Microsoft extension to the ANSI SQL language that includes procedural programming, local variables, and various support functions.
4,591 questions
asked 2023-12-19T13:11:52.4966667+00:00
Kıvanç ÖZDEMİR 125 Reputation points
commented 2024-07-03T04:42:42.13+00:00
Harsh Sugandhi 0 Reputation points
1 answer One of the answers was accepted by the question author.

Sporadic INSERT EXEC failed because the stored procedure altered the schema of the target table

Hi everybody, We're getting this error sporadically. The outer stored procedure has a table variable and it also has a temporary table called #Results which is used to hold results of another stored procedure, e.g. DROP TABLE IF EXISTS…

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,194 questions
Transact-SQL
Transact-SQL
A Microsoft extension to the ANSI SQL language that includes procedural programming, local variables, and various support functions.
4,591 questions
asked 2024-07-02T15:54:40.36+00:00
Naomi Nosonovsky 450 Reputation points
edited a comment 2024-07-02T21:40:08.37+00:00
Erland Sommarskog 105.4K Reputation points MVP
2 answers

Select alternate rows basis on pattern

I have a table like below I want the result like below Please help on this. Thanks in advance.

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,194 questions
Transact-SQL
Transact-SQL
A Microsoft extension to the ANSI SQL language that includes procedural programming, local variables, and various support functions.
4,591 questions
asked 2024-07-01T12:00:38.2466667+00:00
sourav dutta 211 Reputation points
commented 2024-07-02T09:20:11.6233333+00:00
Viorel 114.1K Reputation points
2 answers One of the answers was accepted by the question author.

Preventing Database Deletion in SSMS

prevent accidental database deletions within SQL Server Management Studio (SSMS). Currently, I am exploring options to enforce this restriction effectively implemented a DDL trigger Is the above DDL trigger approach appropriate for preventing…

SQL Server on Azure Virtual Machines
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,194 questions
Transact-SQL
Transact-SQL
A Microsoft extension to the ANSI SQL language that includes procedural programming, local variables, and various support functions.
4,591 questions
asked 2024-06-28T13:20:16.26+00:00
Niket Kumar Singh 300 Reputation points
accepted 2024-07-01T12:12:22.7666667+00:00
Niket Kumar Singh 300 Reputation points
2 answers One of the answers was accepted by the question author.

Query to get Month , Day and Week number of current month.

Hi, Need a query to get Month , Day and Week number of current month.   Sample table   DateMonth NameDayWeekYear6/29/2024JunSatWK52024

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,194 questions
Transact-SQL
Transact-SQL
A Microsoft extension to the ANSI SQL language that includes procedural programming, local variables, and various support functions.
4,591 questions
asked 2024-06-29T10:28:08.37+00:00
mrrobottelg 20 Reputation points
accepted 2024-07-01T06:06:20.8933333+00:00
mrrobottelg 20 Reputation points
5 answers One of the answers was accepted by the question author.

How to calculate Median Value

Suppose i have table and one column has numeric value. now how could i calculate median value ? i found one code from this url https://stackoverflow.com/questions/1342898/function-to-calculate-median-in-sql-server but their approach is not…

Transact-SQL
Transact-SQL
A Microsoft extension to the ANSI SQL language that includes procedural programming, local variables, and various support functions.
4,591 questions
asked 2020-12-13T19:32:57.437+00:00
Sudip Bhatt 2,271 Reputation points
answered 2024-06-28T14:04:48.3766667+00:00
Cédric Hutt 0 Reputation points
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,194 questions
Transact-SQL
Transact-SQL
A Microsoft extension to the ANSI SQL language that includes procedural programming, local variables, and various support functions.
4,591 questions
asked 2024-06-28T05:37:28.5766667+00:00
Elson Wong 0 Reputation points
commented 2024-06-28T06:37:05.3666667+00:00
Elson Wong 0 Reputation points
2 answers One of the answers was accepted by the question author.

Insert with Transaction Significantly Faster than Individual Inserts - SQL Server

Hello, Could you please explain this? Why insert with Transaction significantly faster than individual inserts in SQL Server?

Transact-SQL
Transact-SQL
A Microsoft extension to the ANSI SQL language that includes procedural programming, local variables, and various support functions.
4,591 questions
asked 2021-12-06T14:26:13.723+00:00
Shervan360 1,481 Reputation points
commented 2024-06-27T11:21:02.9166667+00:00
Victor Almeida Schinaider 0 Reputation points
1 answer One of the answers was accepted by the question author.

Sql join query with total row

Hi , please help create table #temp (LedgerID INT, Amount Decimal(18,3)) insert into #temp (LedgerID,Amount) values (121,100),(121,250),(129,25),(129,200),(158,100),(158,500),(157,250),(157,100),(48625,1000) CREATE TABLE #temp_table ( cid INT, type…

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,194 questions
SQL Server Analysis Services
SQL Server Analysis Services
A Microsoft online analytical data engine used in decision support and business analytics, providing the analytical data for business reports and client applications such as Power BI, Excel, Reporting Services reports, and other data visualization tools.
1,258 questions
Transact-SQL
Transact-SQL
A Microsoft extension to the ANSI SQL language that includes procedural programming, local variables, and various support functions.
4,591 questions
asked 2024-06-24T07:11:57.31+00:00
Mohamed Farook 161 Reputation points
accepted 2024-06-27T04:39:03.08+00:00
Mohamed Farook 161 Reputation points
2 answers One of the answers was accepted by the question author.

SP execution time varies with different environment

Dev environment is restored with the latest Test. When a SP with same set of parameter is executed against Test as well as Dev, the execution time is differing with both the environments. In Test it takes 1.45 mins, whereas in Dev it is 3.16/3.08…

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,194 questions
Transact-SQL
Transact-SQL
A Microsoft extension to the ANSI SQL language that includes procedural programming, local variables, and various support functions.
4,591 questions
asked 2024-06-22T12:51:19.8666667+00:00
Radhai Krish 191 Reputation points
accepted 2024-06-27T04:36:38.89+00:00
Radhai Krish 191 Reputation points
1 answer

SQL : Stored Procedure variables if returning 0 or null values do not run next steps

Hi Team - If any of the 4 variables are returning 0 or NULL value do not run the next insert scripts. Could you please help how i can write a condition. TIA Create PROCEDURE [FIN].[Test] @PeriodToAllocate varchar(8) /* */ AS SET NOCOUNT ON DECLARE…

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,194 questions
Transact-SQL
Transact-SQL
A Microsoft extension to the ANSI SQL language that includes procedural programming, local variables, and various support functions.
4,591 questions
asked 2024-06-24T03:21:31.3766667+00:00
kkran 831 Reputation points
answered 2024-06-24T07:21:59.4866667+00:00
LiHongMSFT-4306 25,326 Reputation points
2 answers One of the answers was accepted by the question author.

convert returns conversion error but try_convert does return the correct value

Hi All, I have the following case statement in a TSQL script, which returns the correct negative decimal value, in the rows that acually have a value try_convert (decimal (18,6), max (case when [databody.daysQuality.testResults.testType] =…

Transact-SQL
Transact-SQL
A Microsoft extension to the ANSI SQL language that includes procedural programming, local variables, and various support functions.
4,591 questions
asked 2024-06-17T04:41:27.08+00:00
hans smeets 20 Reputation points
accepted 2024-06-23T20:56:02.5533333+00:00
hans smeets 20 Reputation points
1 answer One of the answers was accepted by the question author.

left and right join

Hi, table 1 Table 2 select A.* from table1a LEFT join table2 b on a.col1=b.col1 output: which is correct but on right join it shows above results how to calculate this join and how it will react on NULL and blank

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,194 questions
Transact-SQL
Transact-SQL
A Microsoft extension to the ANSI SQL language that includes procedural programming, local variables, and various support functions.
4,591 questions
asked 2024-06-23T11:34:41.0833333+00:00
Vineet S 265 Reputation points
commented 2024-06-23T15:26:24.38+00:00
Erland Sommarskog 105.4K Reputation points MVP
2 answers One of the answers was accepted by the question author.

Syntax - How to use variable in LIKE clause

Trying to use a variable in the LIKE clause of a SELECT statement. Hope this is simple, but available guidance hasn't worked. As seen below, query works when a "fixed" value is used with wildcard characters, but I haven't managed to get it with…

Transact-SQL
Transact-SQL
A Microsoft extension to the ANSI SQL language that includes procedural programming, local variables, and various support functions.
4,591 questions
asked 2024-06-20T16:18:26.5933333+00:00
TreyS 166 Reputation points
accepted 2024-06-21T16:24:26.58+00:00
TreyS 166 Reputation points
2 answers One of the answers was accepted by the question author.

elapsed_time value more than query execution time?

I did take query from here in order to check performance of our queries. Executed a SP which took execution time of 1 min 45 seconds. Ran the query from the link which uses the view 'sys.dm_exec_query_stats' Highlighted rows in the screenshots are…

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,194 questions
Transact-SQL
Transact-SQL
A Microsoft extension to the ANSI SQL language that includes procedural programming, local variables, and various support functions.
4,591 questions
asked 2024-06-20T11:09:53.1166667+00:00
Radhai Krish 191 Reputation points
accepted 2024-06-21T05:24:01.7233333+00:00
Radhai Krish 191 Reputation points
2 answers

ID's coming back as nulls are not appearing in my data set

I am trying to create a, intergrity check that bring back data after a record has been cancelled after a certain event. In my query. I am joining to a few tables and I can see all the old cancelled record. When I then cancel any new records, some IDs 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,194 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.
62 questions
Transact-SQL
Transact-SQL
A Microsoft extension to the ANSI SQL language that includes procedural programming, local variables, and various support functions.
4,591 questions
asked 2024-06-19T13:29:32.62+00:00
Kuda 20 Reputation points
answered 2024-06-20T01:25:23.59+00:00
Bruce (SqlWork.com) 60,206 Reputation points
2 answers One of the answers was accepted by the question author.

Unexpected truncation error when inserting from UTF8 to non-UTF8 collation

I believe I am hitting a bug with moving data from a UTF8 to a non-UTF8 collations in SQL Server 2022 CU13 (running under Linux but assuming for now this issue is not related). The issue is that MSSQL appears to be determining the width of a string for…

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,194 questions
Transact-SQL
Transact-SQL
A Microsoft extension to the ANSI SQL language that includes procedural programming, local variables, and various support functions.
4,591 questions
asked 2024-06-11T00:42:42.9533333+00:00
Ben 30 Reputation points
commented 2024-06-18T21:02:02.6166667+00:00
Erland Sommarskog 105.4K Reputation points MVP
3 answers One of the answers was accepted by the question author.

“user_scans” of table “sys.dm_db_index_usage_stats”

I am trying to find answer to the below. What exactly the scan means for the field "user_scans" being with the table "sys.dm_db_index_usage_stats" ? Like, there are tables in our prod which aren't used for sure as the module is…

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,194 questions
Transact-SQL
Transact-SQL
A Microsoft extension to the ANSI SQL language that includes procedural programming, local variables, and various support functions.
4,591 questions
asked 2024-06-17T05:33:15.94+00:00
Radhai Krish 191 Reputation points
accepted 2024-06-18T06:14:28.97+00:00
Radhai Krish 191 Reputation points
4 answers

SSMS freezes on student computer when I demostrate TSQL queries using MS Teams on my computer

I lecture Microsoft SQL courses from my home using Microsoft Teams. I installed the latest edition of SSMS & SQL Dev 2019 Ed on my Lenovo laptop. During the lecture I would share my query window with the delegate to demonstrate TSQL queries. The…

Microsoft Teams
Microsoft Teams
A Microsoft customizable chat-based workspace.
9,478 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,194 questions
Windows 11
Windows 11
A Microsoft operating system designed for productivity, creativity, and ease of use.
8,778 questions
Transact-SQL
Transact-SQL
A Microsoft extension to the ANSI SQL language that includes procedural programming, local variables, and various support functions.
4,591 questions
asked 2023-10-18T21:24:44.0066667+00:00
Marais Viljoen 10 Reputation points
answered 2024-06-17T14:49:01.7833333+00:00
Geoff 0 Reputation points