Questions tagged [tsql]

T-SQL (Transact Structured Query Language) is the extension of SQL functionality supported by Sybase ASE and Microsoft SQL Server. Do not use this tag for MySQL, PostgreSql, Oracle(Pl/SQL) related queries. Please note that SQL code which is being written using LINQ will not also be the part of this tag. This tag specifically created for advanced SQL programming using Microsoft SQL Server.

0 votes
1 answer
35 views

SQL STUFF FOR XML with specific grouping

I'm working in SQL Server 2014, and I have the following simple data, which tracks calling history of users: PhoneNumber Activity ActivityDate ------------------------------------ 9075551234 ...
user avatar
-2 votes
1 answer
29 views

SQL convert Rows to columns without pivot

I have seen several posts on this many of which suggest Pivot. That might be a good solution but my SSMS is 2016 which dose not support Pivot. I am trying to mimic a MS Access report that used VBA to ...
user avatar
0 votes
0 answers
29 views

My string comparison doesn't work with hidden ascii characters

I'm trying to compare the concatenation of two strings like this: SELECT TestChemicalName, ResultChemicalName, CASE WHEN LAB_TestChemicalName + LAB_ResultChemicalName = TestChemicalName + ...
user avatar
  • 5,712
0 votes
0 answers
37 views

Is INSERT INTO...SELECT... a row-by-row-insert operation OR a bulk transaction operation?

Im dealing with some HADR_SYNC_COMMIT waits on my current MSSQL 2016 AG cluster when executing a stored procedure which inserts data into a table (tableA) using another table (tableB) using the INSERT ...
user avatar
  • 1
-1 votes
1 answer
26 views

Select distinct rows with same value in another column

I have a table like this: +--------+----------+ |PersonID|IsDomestic| +--------+----------+ |1 |1 | +--------+----------+ |1 |0 | +--------+----------+ |2 |1 |...
user avatar
  • 324
0 votes
3 answers
31 views

SQL query to add the number of occurrences for current year and all previous years as two numbers

I need help with the following: I have a table called Statuses which contains two columns period, status (this is an example) year Status -------------------- 2021 enrolled 2022 enrolled 2021 enrolled ...
user avatar
  • 1
0 votes
1 answer
31 views

Running total using sum over

I have an AccountEntry table which looks as follows (including the balance computed column im trying to achieve): id PeriodId Date Value FixedValue Balance 1 1 2022-01-01 0 0 0 2 1 2022-01-02 120 0 ...
user avatar
0 votes
0 answers
43 views

Incorrect syntax near '?' when inserting data

I got the status "add successfully" but the data is not inserted to my sql database. However, the data is inserted to SQL database if it is hardcoded. I am wondering the problem arises due ...
user avatar
-1 votes
2 answers
42 views

Transposing a single column table to row

I'm feeling horribly stupid. I can't for the life of me figure out how to transpose the simplest of all cases from a column to a row. All pivot/unpivot whatever examples I find shows complex cases ...
user avatar
  • 2,832
0 votes
1 answer
17 views

How to use a table function outputting 2 columns in an update statement

Pseudocode: Get all projects Use a table function to get all related parts, which uses project id as input and returns 0..* part ids Copy a value from project to all found part ids Datamodel: Table ...
user avatar
0 votes
1 answer
31 views

How to find SQL Object having the text in SQL Server?

There was some performance issue in my application in production, I did some investigation and found out that one process is blocking my SP execution. I saw the log in SolarWinds DPA and found out ...
user avatar
  • 17.6k
0 votes
1 answer
28 views

SQL Server- Get all column names in the table [duplicate]

I have a table name as 'tblOrder', having three columns. I would like to print the column names. I want a script that should return a result as: OrderId Name OrderTrackingNo
user avatar
0 votes
2 answers
46 views

Remove duplicated results using inner join?

I want to see TotalSale values ONLY on the first row of TotalSale that matches with PricesTable DocNumber and DocType SalesTable ProductID DocType DocNumber UnitPrice 01 A 000001 ...
user avatar
0 votes
0 answers
56 views

SQL - Comparing two select statements

I am trying to write a query that performs two select statements across multiple tables using the following ERD: I currently have the following select statements: Query A: SELECT Region....
user avatar
  • 31
-2 votes
0 answers
30 views

Create a new column for table B based on the data from table A [closed]

I want to create a column for table B that are taken from table A. If RunningTotalQtyRecv from table A >= RunningTotalQtyUsed from table B, then return its corresponding QtyRecv. If ...
user avatar

15 30 50 per page
1
2 3 4 5
4737