4,637 questions with Transact-SQL-related tags

Sort by: Updated
0 answers

Pivot query result (column name will change)

Hi there, Working on a huge db task. A small part of it is pivoting a query result with dynamic column names. Example Query: Select top 1 * from information_schema.columns Output should be ColumnName | Value Thanks

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,771 questions
Transact-SQL
Transact-SQL
A Microsoft extension to the ANSI SQL language that includes procedural programming, local variables, and various support functions.
4,637 questions
asked 2024-10-02T23:11:44.2633333+00:00
RJ 166 Reputation points
commented 2024-10-03T06:42:15.3333333+00:00
NIKHILA NETHIKUNTA 2,395 Reputation points Microsoft Vendor
0 answers

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,771 questions
Transact-SQL
Transact-SQL
A Microsoft extension to the ANSI SQL language that includes procedural programming, local variables, and various support functions.
4,637 questions
asked 2024-10-02T23:08:15.1166667+00:00
RJ 166 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,771 questions
Transact-SQL
Transact-SQL
A Microsoft extension to the ANSI SQL language that includes procedural programming, local variables, and various support functions.
4,637 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
0 answers

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,771 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.
97 questions
Transact-SQL
Transact-SQL
A Microsoft extension to the ANSI SQL language that includes procedural programming, local variables, and various support functions.
4,637 questions
asked 2024-10-02T17:24:40.53+00:00
Spunny 326 Reputation points
commented 2024-10-02T18:47:00.79+00:00
Erland Sommarskog 111.1K 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,771 questions
Transact-SQL
Transact-SQL
A Microsoft extension to the ANSI SQL language that includes procedural programming, local variables, and various support functions.
4,637 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,771 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.
97 questions
Transact-SQL
Transact-SQL
A Microsoft extension to the ANSI SQL language that includes procedural programming, local variables, and various support functions.
4,637 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,771 questions
Transact-SQL
Transact-SQL
A Microsoft extension to the ANSI SQL language that includes procedural programming, local variables, and various support functions.
4,637 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,637 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.1K Reputation points
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,771 questions
Transact-SQL
Transact-SQL
A Microsoft extension to the ANSI SQL language that includes procedural programming, local variables, and various support functions.
4,637 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,771 questions
Transact-SQL
Transact-SQL
A Microsoft extension to the ANSI SQL language that includes procedural programming, local variables, and various support functions.
4,637 questions
asked 2024-09-21T20:07:21.3333333+00:00
Vineet S 910 Reputation points
accepted 2024-09-26T02:32:25.3633333+00:00
Vineet S 910 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,771 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.
97 questions
Transact-SQL
Transact-SQL
A Microsoft extension to the ANSI SQL language that includes procedural programming, local variables, and various support functions.
4,637 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.1K Reputation points
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,771 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.
97 questions
Transact-SQL
Transact-SQL
A Microsoft extension to the ANSI SQL language that includes procedural programming, local variables, and various support functions.
4,637 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,016 Reputation points
1 answer One of the answers was accepted by the question author.

DB CM_log.ldf with large size

Hi, I have sccm in the Always On availability group, the CM database size = 5GB but the log file CM_log.ldf = 50GB, how can i reduce the size? thanks.

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,771 questions
Transact-SQL
Transact-SQL
A Microsoft extension to the ANSI SQL language that includes procedural programming, local variables, and various support functions.
4,637 questions
asked 2021-11-04T19:00:52.04+00:00
Lazher YAAKOUBI 381 Reputation points
commented 2024-09-24T22:51:07.3033333+00:00
Vinith Singh 0 Reputation points
1 answer One of the answers was accepted by the question author.

Processing monthly Partition from SQL Job using Stored Procedure

Hello Expert, I have a Tabular model which is having a fact table partitioned monthly on date field. e,g. Partition_July2024, Partition_Aug_2024, Partiton_Sept2024 etc.. I want to create a single SQL job to process these monthly partitions which should…

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,771 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,282 questions
Transact-SQL
Transact-SQL
A Microsoft extension to the ANSI SQL language that includes procedural programming, local variables, and various support functions.
4,637 questions
asked 2024-09-23T06:43:51.1533333+00:00
PANDEY Prashant 125 Reputation points
commented 2024-09-24T11:17:01.93+00:00
PANDEY Prashant 125 Reputation points
2 answers One of the answers was accepted by the question author.

Convert Julian dates in Normal date

How to convert Julian date column in normal date like colum contains 12490,12492 Julian dates

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,771 questions
SQL Server Integration Services
SQL Server Integration Services
A Microsoft platform for building enterprise-level data integration and data transformations solutions.
2,575 questions
Transact-SQL
Transact-SQL
A Microsoft extension to the ANSI SQL language that includes procedural programming, local variables, and various support functions.
4,637 questions
asked 2024-09-19T18:36:21.3566667+00:00
Vineet S 910 Reputation points
accepted 2024-09-23T18:47:18.9466667+00:00
Vineet S 910 Reputation points
4 answers One of the answers was accepted by the question author.

Finding initial size of database datafiles

Hi everybody, Is there a way to determine the initial size of the data files of databases in MS SQL Server? I mean when the data files size is defined with "create database" statement or a backup was restored from another server, or the size…

Transact-SQL
Transact-SQL
A Microsoft extension to the ANSI SQL language that includes procedural programming, local variables, and various support functions.
4,637 questions
asked 2022-04-07T14:59:45.317+00:00
amomen 381 Reputation points
commented 2024-09-20T09:48:07.5133333+00:00
Saverio Lorenzini 0 Reputation points Microsoft Employee
1 answer One of the answers was accepted by the question author.

SQL to Count of Rows Read Inserted Updated Deleted

Hi there, Im looking to log count of row read, inserted, updated, delete while processing data within a SP. Is there any best practice or sp template to catch these counts? You could see inorder to catch the count, the data (millions of rows) is moved…

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,637 questions
asked 2024-09-16T17:52:38.2766667+00:00
RJ 166 Reputation points
commented 2024-09-17T21:27:23.52+00:00
Erland Sommarskog 111.1K Reputation points
3 answers

Way to optimize query where no union needed

I had to use union on two very similar queries where one is just a copy of the other but the having clause is equal with an additional condition in the where clause. Is there a way to clean up the code? DECLARE @PO_DATE_FROM date = '2024-09-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,771 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.
97 questions
Transact-SQL
Transact-SQL
A Microsoft extension to the ANSI SQL language that includes procedural programming, local variables, and various support functions.
4,637 questions
asked 2024-09-10T19:56:39.0933333+00:00
Jonathan Brotto 420 Reputation points
commented 2024-09-17T08:53:22.6933333+00:00
Rodger Kong 90 Reputation points
3 answers One of the answers was accepted by the question author.

Queries in the same window for multiple databases, servers, and tables

I was wondering in SSMS in the query window could I write multiple queries that use different servers, databases, and tables? A compounded question and answer I am expecting 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,771 questions
Not Monitored
Not Monitored
Tag not monitored by Microsoft.
39,057 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.
97 questions
Transact-SQL
Transact-SQL
A Microsoft extension to the ANSI SQL language that includes procedural programming, local variables, and various support functions.
4,637 questions
asked 2024-09-16T13:02:52.5733333+00:00
Jonathan Brotto 420 Reputation points
answered 2024-09-16T21:45:55.07+00:00
Erland Sommarskog 111.1K Reputation points
1 answer One of the answers was accepted by the question author.

Is there any background round operation for floats?

select ceiling(1285.0992 / 1.94712) result for the query above is 660 but the query below gives 661 as a result. declare @var1 float = 1285.0992 declare @var2 float = 1.94712 select ceiling(@var1 / @var2) can anyone tell me how that 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,771 questions
Transact-SQL
Transact-SQL
A Microsoft extension to the ANSI SQL language that includes procedural programming, local variables, and various support functions.
4,637 questions
asked 2024-09-04T14:58:43.98+00:00
Yavuz RA 20 Reputation points
accepted 2024-09-13T13:28:09.2133333+00:00
Yavuz RA 20 Reputation points