4,685 questions with Transact-SQL-related tags

Sort by: Updated
3 answers

Best practices for joining tables of different collation property database

Hi, I am trying to join two tables of databases present on same server but with different collation property and getting following error: What are the best practices to join tables of different databases present on same server but with different…

SQL Server
SQL Server
A family of Microsoft relational database management and analysis systems for e-commerce, line-of-business, and data warehousing solutions.
14,400 questions
Transact-SQL
Transact-SQL
A Microsoft extension to the ANSI SQL language that includes procedural programming, local variables, and various support functions.
4,685 questions
asked 2025-01-30T10:48:40.5633333+00:00
Priya Jha 876 Reputation points
answered 2025-01-30T22:40:37.0866667+00:00
Erland Sommarskog 116.1K Reputation points MVP
3 answers One of the answers was accepted by the question author.

An expression of non-boolean type specified in a context where a condition is expected

Hi, I have an issue with this stored procedure (code below), it returns me the following error: An expression of non-boolean type specified in a context where a condition is expected, near 'seque'. Can you please help me with it ? Thank you 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.
14,400 questions
Transact-SQL
Transact-SQL
A Microsoft extension to the ANSI SQL language that includes procedural programming, local variables, and various support functions.
4,685 questions
asked 2021-05-07T11:06:17.85+00:00
Naami.Ayman 331 Reputation points
commented 2025-01-30T08:11:43.1366667+00:00
Moses Ogada 0 Reputation points
2 answers One of the answers was accepted by the question author.

Scalability LEFT JOIN vs MERGE

Hi there, I'm UPSERTING AND handling 70 + millions of rows of UPSERT. I'm the only developer on the DB. GP_Gen5_6 LEFT JOIN DURING UNIT TEST OF ALL RECORDS 12 mins SCALED UP OVERNIGHT PROCESS GP_Gen5_20 History of existing MERGE process same operation…

Azure SQL Database
Transact-SQL
Transact-SQL
A Microsoft extension to the ANSI SQL language that includes procedural programming, local variables, and various support functions.
4,685 questions
asked 2025-01-28T17:04:24.43+00:00
RJ 286 Reputation points
accepted 2025-01-29T16:02:55.4066667+00:00
RJ 286 Reputation points
2 answers One of the answers was accepted by the question author.

Select with Conditional COUNT

Hello everyone and thanks for the help in advance. In a prevous post https://learn.microsoft.com/en-us/answers/questions/2148980/counting-occurrences-in-a-table, Erland Sommarskog built a query for me that counted the occurrences of vaccines by patient.…

SQL Server
SQL Server
A family of Microsoft relational database management and analysis systems for e-commerce, line-of-business, and data warehousing solutions.
14,400 questions
Transact-SQL
Transact-SQL
A Microsoft extension to the ANSI SQL language that includes procedural programming, local variables, and various support functions.
4,685 questions
asked 2025-01-27T23:07:18.69+00:00
Kmcnet 926 Reputation points
commented 2025-01-28T22:08:15.4233333+00:00
Kmcnet 926 Reputation points
2 answers

Invalid object name 'STRING_SPLIT' in SQL Server 2019

Hi Support, Our SQL server version is 2019 and check the compatibility level is 150, but it still have error "Invalid object name 'STRING_SPLIT' ". We also tried the case sensitive according to this link, both of them have the same error. …

SQL Server
SQL Server
A family of Microsoft relational database management and analysis systems for e-commerce, line-of-business, and data warehousing solutions.
14,400 questions
Transact-SQL
Transact-SQL
A Microsoft extension to the ANSI SQL language that includes procedural programming, local variables, and various support functions.
4,685 questions
asked 2022-04-04T02:26:23.81+00:00
Chong 871 Reputation points
commented 2025-01-27T07:14:17.7333333+00:00
Jindra 0 Reputation points
1 answer One of the answers was accepted by the question author.

How to figure out the total number of doses within a time span given to a client as dose are being added and stopped.?

If the cadence values are different, even if the dates overlap the records must be separate. If an order for the same dose and cadence value (including nulls) starts on the same day or the next day (+or-1 day) the record should continue. outlook of…

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.
114 questions
Transact-SQL
Transact-SQL
A Microsoft extension to the ANSI SQL language that includes procedural programming, local variables, and various support functions.
4,685 questions
asked 2024-07-22T22:24:04.8633333+00:00
andrew omofonma 61 Reputation points
edited the question 2025-01-27T04:28:08.7933333+00:00
Rakesh Gurram 11,630 Reputation points Microsoft Vendor
3 answers One of the answers was accepted by the question author.

Run SQL Statements Parallel within a SP

Hi there, Is there a way to run SQL Statements in parallel within the same SP? Thanks for your time. CREATE PROCEDURE CustomerPARALLEL AS BEGIN EXEC DBO.CUST1 - TAKES 20 MINS (INDEPENDENT) EXEC DBO.CUST2 - (TAKES 20 MINS (NO DEPENDENCY)) HOW TO…

Azure SQL Database
Transact-SQL
Transact-SQL
A Microsoft extension to the ANSI SQL language that includes procedural programming, local variables, and various support functions.
4,685 questions
asked 2025-01-22T18:28:57.0533333+00:00
RJ 286 Reputation points
answered 2025-01-25T22:29:15.7166667+00:00
Erland Sommarskog 116.1K Reputation points MVP
10 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,397 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.
14,400 questions
Transact-SQL
Transact-SQL
A Microsoft extension to the ANSI SQL language that includes procedural programming, local variables, and various support functions.
4,685 questions
asked 2023-12-19T13:11:52.4966667+00:00
Kıvanç ÖZDEMİR 135 Reputation points
answered 2025-01-25T19:04:25.2733333+00:00
Joshua Moonstar 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,685 questions
asked 2024-09-26T13:24:49.4666667+00:00
LUIXANY COLISEE 0 Reputation points
commented 2025-01-24T16:40:24.2966667+00:00
GlockByte 161 Reputation points
1 answer

SQL gaps and island issue

Greetings!!! We're working on migrating data from a legacy application and have a requirement to get all the consecutive SESSION START_DATE & END_DATE. For the SESSION_ID - 8642, SESSION_TYPE - 3256, based on the requirement using sql server query…

SQL Server
SQL Server
A family of Microsoft relational database management and analysis systems for e-commerce, line-of-business, and data warehousing solutions.
14,400 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.
114 questions
Transact-SQL
Transact-SQL
A Microsoft extension to the ANSI SQL language that includes procedural programming, local variables, and various support functions.
4,685 questions
asked 2025-01-21T05:59:20.4966667+00:00
Raj D 591 Reputation points
commented 2025-01-23T22:35:07.0133333+00:00
Erland Sommarskog 116.1K Reputation points MVP
1 answer One of the answers was accepted by the question author.

A Simple SQL Query

I have the following table:- I want Col 1 and Col 2 where Col2 =1 and the corresponding all the values of Col 1 where Col 1 =2. But this is an example. I can find 1st part (i.e,, Select Col1, Col 2 from Table1 where Col 2 =1). But my problem is how do…

SQL Server
SQL Server
A family of Microsoft relational database management and analysis systems for e-commerce, line-of-business, and data warehousing solutions.
14,400 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.
114 questions
Transact-SQL
Transact-SQL
A Microsoft extension to the ANSI SQL language that includes procedural programming, local variables, and various support functions.
4,685 questions
asked 2025-01-21T14:07:34.2966667+00:00
chuck DM 101 Reputation points
commented 2025-01-22T07:23:58.6166667+00:00
Olaf Helper 45,776 Reputation points
3 answers One of the answers was accepted by the question author.

Find ALL UNUSED columns on SQL DB Tables

Hi there, Is there a way in AZURE SQL Server to find all columns of a table which are NOT used by ANY SPs or Views. I have 65000+ columns in DB based on information schema columns. I do see 200+ SPs of which not all columns are used. Some have select *…

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.
14,400 questions
Transact-SQL
Transact-SQL
A Microsoft extension to the ANSI SQL language that includes procedural programming, local variables, and various support functions.
4,685 questions
asked 2025-01-21T17:05:11.6733333+00:00
RJ 286 Reputation points
accepted 2025-01-21T22:18:50.0366667+00:00
RJ 286 Reputation points
1 answer

How to write a Simple TSQL

I have the following table:- I have two requirements. the 1st one is, I need ColA and ColB when ColB is 1. So the query would be:- Select ColA, ColB from Table1 where ColB =1. The Output of the 1st requirement is:- Now the 2nd requirement is, as 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.
114 questions
Transact-SQL
Transact-SQL
A Microsoft extension to the ANSI SQL language that includes procedural programming, local variables, and various support functions.
4,685 questions
asked 2025-01-21T14:52:01.98+00:00
chuck DM 101 Reputation points
edited an answer 2025-01-21T14:56:51.59+00:00
Viorel 119.3K Reputation points
1 answer One of the answers was accepted by the question author.

UPSERT - CAPTURE UPDATED ROWS INTO ANOTHER AUDIT TABLE

Hi there, I'm trying to do soft delete on a target table which are not in source. Basically if the ID is not in source but ID is in target, update that RecordStatusKey of that specific target ID. I would like to capture the records updated in merge. 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.
14,400 questions
Transact-SQL
Transact-SQL
A Microsoft extension to the ANSI SQL language that includes procedural programming, local variables, and various support functions.
4,685 questions
asked 2025-01-20T17:01:10.7433333+00:00
RJ 286 Reputation points
accepted 2025-01-20T22:57:55.0666667+00:00
RJ 286 Reputation points
1 answer One of the answers was accepted by the question author.

Counting Occurrences in a Table

Hello everyone and thanks for the help in advance. I need to develop a MVC application that reads a SQL database of patients who have received vaccines. The table looks like: [ID] [int] IDENTITY(1,1) NOT NULL, [MRNumber] [varchar](50)…

ASP.NET Core
ASP.NET Core
A set of technologies in the .NET Framework for building web applications and XML web services.
4,767 questions
Transact-SQL
Transact-SQL
A Microsoft extension to the ANSI SQL language that includes procedural programming, local variables, and various support functions.
4,685 questions
asked 2025-01-19T02:44:58.7666667+00:00
Kmcnet 926 Reputation points
accepted 2025-01-20T19:59:16.7966667+00:00
Kmcnet 926 Reputation points
3 answers

@@ROWCOUNT issue

Hi there, I had the below code and it worked fine in counting the records inserted and logging insert counts. CREATE PROCEDURE ProcessCustomer AS BEGIN DECLARE @RowsInserted INT; -- Insert into the final table and capture row count …

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.
14,400 questions
Transact-SQL
Transact-SQL
A Microsoft extension to the ANSI SQL language that includes procedural programming, local variables, and various support functions.
4,685 questions
asked 2025-01-11T05:26:26.6833333+00:00
RJ 286 Reputation points
commented 2025-01-18T20:58:35.1066667+00:00
Erland Sommarskog 116.1K Reputation points MVP
3 answers

Strip non numeric characters from string

Hi there, Happy New Year! I'm creating a new table (billions of records). I need to strip non numeric values from a column. Input '.I82807- R%' Output 82807 i created a function based on online however ITS SLOOOOOWWWWWW.... Wanted to check if…

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.
14,400 questions
Transact-SQL
Transact-SQL
A Microsoft extension to the ANSI SQL language that includes procedural programming, local variables, and various support functions.
4,685 questions
asked 2025-01-03T17:20:48.4066667+00:00
RJ 286 Reputation points
commented 2025-01-16T07:42:29.8566667+00:00
LiHongMSFT-4306 30,511 Reputation points
2 answers One of the answers was accepted by the question author.

How do I update DBContext after adding new table to SQL database?

We added a new table to our SQL Server database called Occupation. From the ASP.NET Web Form project, I can not seem to access it. Imports System.Data.Entity Public Class CCDBContext Inherits DbContext Public Sub New() …

ASP.NET
ASP.NET
A set of technologies in the .NET Framework for building web applications and XML web services.
3,586 questions
VB
VB
An object-oriented programming language developed by Microsoft that is implemented on the .NET Framework. Previously known as Visual Basic .NET.
2,775 questions
Transact-SQL
Transact-SQL
A Microsoft extension to the ANSI SQL language that includes procedural programming, local variables, and various support functions.
4,685 questions
asked 2025-01-11T17:50:11.4366667+00:00
Joe Pool (Heartland) 20 Reputation points
commented 2025-01-13T14:35:25.85+00:00
Joe Pool (Heartland) 20 Reputation points
2 answers One of the answers was accepted by the question author.

Avoid unnecessary updates on MERGE UPSERT

Hi there, You all might have used UPSERT operation using MERGE. Currently the update section updates all rows once the key is matched. Is there a way to update only rows which have column value changed and not update all rows to avoid unnecessary updates…

Azure SQL Database
Transact-SQL
Transact-SQL
A Microsoft extension to the ANSI SQL language that includes procedural programming, local variables, and various support functions.
4,685 questions
asked 2025-01-09T16:08:24.4733333+00:00
RJ 286 Reputation points
accepted 2025-01-09T17:05:02.9166667+00:00
RJ 286 Reputation points
1 answer One of the answers was accepted by the question author.

Identify the users with minimum votes and allocate new votes to that user in Synapse SQL

Hello Experts I came up with one problem where I am looking for a solution as I have two tables: Table1: Users |UserID | TotalTasks| | A3 | 12 | | A4 | 14 | | A5 | 11 | Table2: Tasks | TaskID | NewTask| | 1 …

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.
5,157 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.
14,400 questions
Transact-SQL
Transact-SQL
A Microsoft extension to the ANSI SQL language that includes procedural programming, local variables, and various support functions.
4,685 questions
asked 2024-12-27T17:28:31.5566667+00:00
Avanish Tomar 20 Reputation points
commented 2025-01-02T08:14:30.27+00:00
Avanish Tomar 20 Reputation points