216 questions with SQL Server | SQL Server Transact-SQL tags

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

T-SQL optimization needed

Hi everybody, I have the following code which I have commented: --CASE -- WHEN Status = 'Termed' THEN -- CASE -- WHEN ProviderType IN ( 'Group, Solo' ) THEN -- NULL …

SQL Server | SQL Server Transact-SQL
asked 2025-08-19T13:08:32.61+00:00
Naomi Nosonovsky 8,491 Reputation points
commented 2025-08-24T20:09:04.48+00:00
Joerg 62 191 Reputation points
3 answers

How to find Missing non clustered Indexes

Is there way to find Missing non clustered Indexes on Particular Database? Thank you

SQL Server | SQL Server Transact-SQL
asked 2025-08-12T15:50:01.7033333+00:00
Jinal Contractor 121 Reputation points
answered 2025-08-22T06:31:12.5433333+00:00
Victor Garret 0 Reputation points
1 answer

Which T-SQL statement should be used to instruct a database management system to use an index instead of performing a full table scan?

Hello everyone, I am currently preparing for the DP-900: Microsoft Azure Data Fundamentals exam and would like to get an expert's clarification on a specific question. The question is as follows: Which T-SQL statement or clause should be used to…

SQL Server | SQL Server Transact-SQL
asked 2025-08-19T14:21:02.75+00:00
Anabella Noemi Santillan 0 Reputation points
accepted 2025-08-21T13:59:27.4233333+00:00
Anabella Noemi Santillan 0 Reputation points
3 answers

Using IsNull with different data types in SQL SERVER

Hi Team, I am working on on premises SQL Server. I have a requirement where I need to apply left outer join between 2 tables and use IsNull to show default data when columns are having null. Under ISNULL, if a column is null what shall i put for below…

SQL Server | SQL Server Transact-SQL
asked 2025-06-06T18:06:46.15+00:00
Salil Singh 60 Reputation points
answered 2025-08-21T13:17:24.7466667+00:00
Don Price 0 Reputation points
1 answer

4K supported Disk is the new one. But still in the Windows 11 Pro with 4K disk doesn't support SQL 2022 or 2019 express edition. What is the solution for that?

It is limitation or any specific concern. I can not install 2019/2022 express in my laptop which disk is 4K -native. Whats should be the solution?

SQL Server | SQL Server Transact-SQL
asked 2025-08-20T08:53:06.43+00:00
Sandip Patel 0 Reputation points
commented 2025-08-20T15:34:01.3266667+00:00
Viorel 123.8K Reputation points
0 answers

Invalid object name cte

Hello everyone, Why invalid object name cte appears on the second line in this valid query in run-time: SELECT 'Automation OHCS' AS source, cte.Request_Type, cte.Change_Type, cte.[Exclusion_Reason], --…

SQL Server | SQL Server Transact-SQL
asked 2025-08-19T16:18:51.7433333+00:00
Naomi Nosonovsky 8,491 Reputation points
commented 2025-08-19T16:33:19.1+00:00
Naomi Nosonovsky 8,491 Reputation points
2 answers One of the answers was accepted by the question author.

How to Calculate salary of employee

I am calculating salary using below query SELECT '29' as Total_Days,'28' as Present_Days, (14000 / 29) AS Per_Day, (14000 / 29) * 28 AS Total_Salary; But Total_Salary should be 14000 because Total_Days 29 and Present_Day 29

SQL Server | SQL Server Transact-SQL
SQL Server | Other
asked 2024-04-27T06:08:58.23+00:00
Analyst_SQL 3,576 Reputation points
answered 2025-08-19T09:33:24.4833333+00:00
Hena Ortag 0 Reputation points
0 answers

The query processor ran out of internal resources and could not produce a query plan. This is a rare event and only expected for extremely complex queries or queries that reference a very large number of tables or partitions. Please simplify the query. If

Good day, I am getting this error: The query processor ran out of internal resources and could not produce a query plan. This is a rare event and only expected for extremely complex queries or queries that reference a very large number of tables or…

SQL Server | SQL Server Transact-SQL
asked 2025-08-04T22:07:12.9+00:00
Naomi Nosonovsky 8,491 Reputation points
commented 2025-08-05T23:53:30.99+00:00
Naomi Nosonovsky 8,491 Reputation points
1 answer One of the answers was accepted by the question author.

How to alter default_schema

Here's my problem: Logged into SQL Server with default Windows authentication, Username = [mydomain\CoreyF] Created a table "mytable" Executed "SELECT * FROM INFORMATION_SCHEMA.TABLES" The default schema shows…

SQL Server | SQL Server Transact-SQL
asked 2025-08-01T19:14:09.6033333+00:00
Corey Fleig 100 Reputation points
commented 2025-08-02T00:20:02.82+00:00
Corey Fleig 100 Reputation points
1 answer

I created connections via mssql extension in vs code and now when I click on mssql, I don't see them.

I saved database connections in via mssql extension in vs code and now when I click on mssql, I don't see them. All I see when I click on the mssql icon is this.

SQL Server | SQL Server Transact-SQL
asked 2025-07-25T20:19:25.4233333+00:00
Amy Petrone 0 Reputation points
edited an answer 2025-07-25T21:40:32.1933333+00:00
Bruce (SqlWork.com) 79,526 Reputation points Volunteer Moderator
2 answers One of the answers was accepted by the question author.

Missing column values

Hi, I have sample student data as in the below. CREATE TABLE [dbo].[test_table]( [ID] [bigint] NULL, [Score] [numeric](38, 6) NOT NULL, [Ratio] [numeric](38, 6) NOT NULL, [Desc] [varchar](50) NULL, [Report] [varchar](8) NULL ) ON…

SQL Server | SQL Server Transact-SQL
asked 2025-07-24T04:52:41.85+00:00
Rontech10111 181 Reputation points
accepted 2025-07-24T11:47:58.9966667+00:00
Rontech10111 181 Reputation points
1 answer One of the answers was accepted by the question author.

How to update existing columns during insert

Greetings! I have a SQL job that runs the following SQL script every Monday. WITH Result1 AS ( select p.Customer, p.ProductNumber, p.CurrentCost from price p ) --Main Select insert into Price_Archive ( [DateTime], [Customer], [ProductNumber],…

SQL Server | SQL Server Transact-SQL
asked 2025-07-23T13:13:29.74+00:00
Mizuno8482 20 Reputation points
commented 2025-07-23T14:54:22.56+00:00
Mizuno8482 20 Reputation points
2 answers

Latest security update has caused SS debugger to fail... 2008 r2 windows 10 - Windows Firewall

Getting: The WIndows Firewall on this machine is currently blocking remote debugging. RD requires... TCP Port 135... UDP 4500/ 500 be unblocked. Can't Cancel, Unlock for local or Unlock for Computer. Trying to "Debug>Start Debugging".

SQL Server | SQL Server Transact-SQL
asked 2025-07-12T01:50:50.6933333+00:00
M Douglas Martin 0 Reputation points
commented 2025-07-17T18:06:02.4033333+00:00
M Douglas Martin 0 Reputation points
1 answer One of the answers was accepted by the question author.

need a query for a match 2

Hi all, I have these two tables: T1 Date Item Qty 2025-07-01 100 10 2025-07-01 101 20 2025-07-01 102 20 2025-07-01 105 30 2025-07-02 100 30 2025-07-03 200 20 2025-07-03 201 25 2025-07-03 202 40 2025-07-04 200 30 and T2 Date …

SQL Server | SQL Server Transact-SQL
asked 2025-07-11T18:10:16.52+00:00
elsvieta 416 Reputation points
commented 2025-07-15T12:28:08.22+00:00
elsvieta 416 Reputation points
1 answer

Assigning large text block to nvarchar(max) SOMETIMEs truncates at 4000 bytes

I have a really large dynamic sql query (19,000+ in length) that is assigned to @SQLText nvarchar(max). Everything was working. Made some minor changes and then @SQLText variable only contained 4000 characters, truncating the rest of the query text.…

SQL Server | SQL Server Transact-SQL
asked 2025-07-14T15:30:33.5+00:00
Grossnickle, Brenda 120 Reputation points
commented 2025-07-14T16:53:33.51+00:00
Grossnickle, Brenda 120 Reputation points
1 answer One of the answers was accepted by the question author.

need a query to do a match

Hi all, I have these two tables: T1 Date Item Qty 2025-07-01 100 10 2025-07-01 101 20 2025-07-02 100 30 2025-07-03 200 20 2025-07-04 200 30 and T2 Date Item …

SQL Server | SQL Server Transact-SQL
asked 2025-07-09T15:21:43.62+00:00
elsvieta 416 Reputation points
commented 2025-07-11T17:43:53.7433333+00:00
elsvieta 416 Reputation points
1 answer

Documentation for CLR-Based Alternatives to xp_cmdshell

Hi Team, Since extended stored procedures are deprecated, is there any source code or documentation available for a CLR-based alternative to Microsoft system-defined extended stored procedures such as xp_cmdshell? Thanks, Abhishek Modi

SQL Server | SQL Server Transact-SQL
asked 2025-07-08T06:13:40.6066667+00:00
Abhishek Modi (amodi) 0 Reputation points
commented 2025-07-09T07:52:15.66+00:00
Erland Sommarskog 124.9K Reputation points MVP Volunteer Moderator
1 answer

Power Apps SQL Update Taking Time – Need Help with Efficient Bulk Update via Staging Table and Dynamic SP.

Question: We are currently using Power Apps to perform manual data reconciliation between two tables — let’s say TBL-1 and TBL-2 (as shown in the screenshot below). Our users upload data from Excel via Power Apps and click “Update,” which triggers SQL…

SQL Server | SQL Server Transact-SQL
asked 2025-07-07T15:56:38.7+00:00
Dheeraj Singh 0 Reputation points
answered 2025-07-07T20:12:59.29+00:00
Erland Sommarskog 124.9K Reputation points MVP Volunteer Moderator
1 answer

Joins vs Functions and Performance

It is axiomatic that joining to another table from your primary table to retrieve data, using primary keys, provides better performance than using a function. At least that's what I know from the last time I cared about it years ago. It's time to care…

SQL Server | SQL Server Transact-SQL
asked 2025-07-03T19:12:57.03+00:00
Don Thompson 0 Reputation points
answered 2025-07-03T19:48:52.9233333+00:00
Erland Sommarskog 124.9K Reputation points MVP Volunteer Moderator
0 answers

[SQLServer JDBC Driver][SQLServer]An expression of non-boolean type specified in a context where a condition is expected, near

Hi, I'm getting the following error: [SQLServer JDBC Driver][SQLServer]An expression of non-boolean type specified in a context where a condition is expected, near 'Jul' Here is the code: select 'Actual' SCENARIO, #PROGRESS_TO_HFM.P_YEAR …

SQL Server | SQL Server Transact-SQL
asked 2025-06-20T10:11:18.2766667+00:00
Eldo Mills 0 Reputation points
commented 2025-06-24T12:44:15.83+00:00
Eldo Mills 0 Reputation points