114 questions with SQL Server Transact-SQL tags

Sort by: Updated
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,684 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,550 Reputation points Microsoft Vendor
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,389 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,684 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,389 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,684 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
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,684 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.2K Reputation points
1 answer

Need tsql to find index usage on views

I have some views that have indexes and i want to get their usage - seeks, scan, lookups - but i cannot find the tsql code.

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
asked 2025-01-15T22:35:28+00:00
Grossnickle, Brenda 80 Reputation points
commented 2025-01-16T22:07:15.1833333+00:00
Erland Sommarskog 116.1K Reputation points MVP
1 answer One of the answers was accepted by the question author.

Seeking advice on deleting Indexes

Re: Seeking advice on deleting Indexes We have a nightly ETL with a table update that runs about 90 minutes that i want to optimize. There is a WHILE loop that executes 24 times (And no, there is no way to take the WHILE loop out of the processing 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.
114 questions
asked 2025-01-15T20:37:57.7666667+00:00
Grossnickle, Brenda 80 Reputation points
accepted 2025-01-15T22:40:41.9966667+00:00
Grossnickle, Brenda 80 Reputation points
4 answers One of the answers was accepted by the question author.

Invalid output when trying to invoke stored-procedure returning output from entityframework core -

Hi gents, can you sort out the following for me. Let me explain the scenario in detail. I have a MSSQL stored procedure that returns me output value. The output value is of int type. Stored Procedure: CREATE procedure…

Entity Framework Core
Entity Framework Core
A lightweight, extensible, open-source, and cross-platform version of the Entity Framework data access technology.
774 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
Entity Framework Core Training
Entity Framework Core Training
Entity Framework Core: A lightweight, extensible, open-source, and cross-platform version of the Entity Framework data access technology.Training: Instruction to develop new skills.
5 questions
asked 2025-01-06T17:02:27.0333333+00:00
P. G. Choudhury 121 Reputation points
edited the question 2025-01-08T01:40:07.3133333+00:00
Jack J Jun 24,631 Reputation points Microsoft Vendor
1 answer

Alternative approaches for Recursive CTE in SQL server. The data is 1 million records. need to calculate the current value based on previous value and iterate through Million records. Please suggest a methods which performs better than Recursive CTE

here is the query for your reference. Thanks! Alternative approaches for Recursive CTE in SQL server. The data is 1 million records. need to calculate the current value based on previous value and iterate through Million records. Please suggest a…

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,389 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,684 questions
asked 2024-12-24T08:30:28.83+00:00
roopa g 20 Reputation points
answered 2024-12-25T01:53:37.3033333+00:00
LiHongMSFT-4306 30,511 Reputation points
1 answer

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.
14,389 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,684 questions
asked 2024-05-09T18:55:45.0266667+00:00
Bobby P 231 Reputation points
commented 2024-12-24T09:16:39.78+00:00
Erland Sommarskog 116.1K Reputation points MVP
3 answers One of the answers was accepted by the question author.

How to get the current row value based on previous row value in sql server- ex first row has value, calculate the second row value using first row and some conditions and 3rd using 2nd row and same conditions

when basin <> prebasin, numberinbasinnew=numberinbasin. when basin=prebasin use the numberinbasinnew from the first row (basin<>prebasin) and calculate the second row value for numberinbasinnew based on below conditions -- CASE …

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,389 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,684 questions
asked 2024-12-19T11:36:41.54+00:00
roopa g 20 Reputation points
accepted 2024-12-24T08:33:34.1733333+00:00
roopa g 20 Reputation points
1 answer

Sql server how to change column type from int to date

Sql server how to change column type from int to date

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
asked 2024-12-18T20:15:02.31+00:00
Shannon Shen 0 Reputation points
answered 2024-12-18T22:22:03.6+00:00
Erland Sommarskog 116.1K Reputation points MVP
1 answer

"Data Flow Task:Error: SSIS Error Code DTS_E_CANNOTACQUIRECONNECTIONFROMCONNECTIONMANAGER. The AcquireConnection method call to the connection manager ""Oracle_XXXX"" failed with error code 0xC0014009. There may be error messages posted before this

SSIS using task factory component and brings data from Oracle to SQL Server. SSIS package execute successfully on dev SQL Server environment and it returns errors on production. It runs scheduled as a job. Both servers are 2019 and identical. Here is 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.
14,389 questions
Windows Server
Windows Server
A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.
13,609 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
asked 2024-12-12T17:24:56.3333333+00:00
Gena Tamarov 1 Reputation point
commented 2024-12-17T03:32:03.8366667+00:00
Vijayalaxmi Kattimani 985 Reputation points Microsoft Vendor
2 answers One of the answers was accepted by the question author.

remove duplicates

hi all, I have this kind of duplicates: ID Line Amount === === ====== 100 1 1000 100 2 100 100 1 100 100 2 1000 101 1 2000 101 2 500 101 3 …

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,389 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
asked 2024-12-10T18:49:51.5+00:00
elsvieta 371 Reputation points
commented 2024-12-12T12:42:25.7066667+00:00
elsvieta 371 Reputation points
2 answers One of the answers was accepted by the question author.

Account ledger query with debit and credit

Hi All respected community member, i am trying to develop ledger query from long time still i could not get ,please do review and help me out , if you have any suggestion for restructure #tbl_Transection_test table ,please let me know or guide me…

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,389 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,684 questions
asked 2024-11-26T10:07:32.43+00:00
Analyst_SQL 3,576 Reputation points
accepted 2024-11-28T06:56:43.5266667+00:00
Analyst_SQL 3,576 Reputation points
2 answers One of the answers was accepted by the question author.

Split one column into multiple column

Dear my friends, I have a question about how to split one column into multiple column ? I've try the code but it doesn't work Does anyone could help me ? Thank You for your help Best Regards, Steve Henry

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,389 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,684 questions
asked 2024-11-08T02:30:55.4366667+00:00
Steven Henry Suhendra 20 Reputation points
commented 2024-11-08T07:02:36.26+00:00
Steven Henry Suhendra 20 Reputation points
0 answers

SQL Stored Procedure BULK INSERT wont execute when called from Kubernetes Cluster

Hi There, I have a Python Program that calls a Stored Procedure on a SQL Managed Instance in Azure. This stored procedure, deletes data from a staging table and carries out a BULK INSERT of Data from CSV files that are stored in a Storage Account…

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,389 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
asked 2024-10-30T08:21:27.5466667+00:00
Chris Courtney 20 Reputation points
commented 2024-10-30T22:37:59.94+00:00
Erland Sommarskog 116.1K Reputation points MVP
1 answer

Correct SQL query to not repit articles

Hello, good afternoon, I have the following query in SQL and it is returning duplicate items. I managed to decipher that the items that are duplicated in the "On Orders" column in one row appear with one quantity and in the next row (Same item,…

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,389 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,684 questions
asked 2024-10-24T18:39:13.1333333+00:00
Javier Prieto 1 Reputation point
commented 2024-10-24T23:26:16.4633333+00:00
Javier Prieto 1 Reputation point
1 answer One of the answers was accepted by the question author.

CURSOR for column in WHERE that gives dynamic columns in SELECT

Hello, I need help to make my query more simple Depends how many rows for column Code (now I have 53 rows) then it will be 53 sub selects and 53 more columns. How to make it simple to add variable in select and in sub select instead of writing 53 times…

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,389 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,684 questions
asked 2024-10-20T20:25:46.2966667+00:00
Alan5896 26 Reputation points
commented 2024-10-21T21:20:32.78+00:00
Erland Sommarskog 116.1K Reputation points MVP
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.
14,389 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,684 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 116.1K Reputation points MVP
1 answer One of the answers was accepted by the question author.

Runing SSAS Tabular Processing Script (TMSL) from SSAS Database Engine

Hello Experts, In continuation of my previous question https://learn.microsoft.com/en-us/answers/questions/2076521/processing-monthly-partition-from-sql-job-using-st?source=docs We have SSAS Tabular model database and SSAS Database engine. When trying 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.
14,389 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,308 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
asked 2024-09-24T11:15:03.1866667+00:00
PANDEY Prashant 145 Reputation points
accepted 2024-10-14T06:50:21.2266667+00:00
PANDEY Prashant 145 Reputation points