All Questions
Tagged with subquery sql-server-2012
15 questions
0
votes
1
answer
159
views
How can I improve the run time of a query that groups / display same date data in one row?
I currently have a view that contains about 1k rows of user information. currently i have a query that groups all the same user information by date into one row. Currently this query takes between 20 ...
0
votes
1
answer
1k
views
Query to Find Multiple Start Time and End Time on a Single Day based on Boolean Value
I want to find the multiple Start Time and End time in a single Day based on the Boolean value where data is divided into each half hour interval for a day. So Each day is divided into 24hrs/2 = 48. ...
0
votes
1
answer
516
views
Using a Calculated Field in a Separate Calculated Field
I'm trying to avoid creating a temp table for just one single field, but I need to use a calculated field in a separate calculated field. For example:
,CASE WHEN ln.INT_RATE_CODE = 'A' THEN 1
...
2
votes
2
answers
22k
views
how to add loop in date column in sql through query? [duplicate]
If ID = 01234 and this ID has done transaction in 3 time in a month like this:
***DAY_no Balance***
1/1/2018 5000
10/1/2018 10000
15/1/2018 ...
0
votes
3
answers
2k
views
SQL Server 2012 Query: Invoices with Earliest Date in State for each Vendor
I have the tables:
Invoices ( VendorID, InvoiceDate, InvoiceNumber, InvoiceTotal,...),
Vendors (VendorName, VendorID,....)
I am trying to obtain a list of the earliest invoices for each vendor, ...
2
votes
4
answers
2k
views
Vendors with Most Invoices in State
I have the tables Vendors(VendorName, VendorID,...) and Invoices(InvoiceID,...) and I am trying to find vendors with the most invoices in their respective states. Please critique my work:
SELECT Max(...
2
votes
2
answers
842
views
Correlated subquery to find total larger than state average
I have tables Vendors (VendorName, VendorState,....) and Invoices (InvoiceID, InvoiceTotal,...). I want to get the Invoices (as InvoiceId) that are larger than the Avg state InvoiceTotal.
I know I ...
0
votes
2
answers
642
views
Error When Trying to Run Subquery
I am having issues getting my subquery to run properly. Everything runs quickly and correctly until I add the subquery. I get the error:
"Msg 4145, Level 15, State 1, Line 66
An expression of non-...
4
votes
2
answers
3k
views
Outer self join filters vs subqueries
I have a table storing information about tickets. There is one record when ticket is sold and another when ticket is used. There is a column called TransType which is set to either 'sold' or 'used' ...
1
vote
2
answers
339
views
Referencing a SELECT subquery value in the WHERE clause
Complete query
SET @vSelect =
'
SELECT
T1.BranchShortName AS BranchShortName,
(
SELECT TT1.EmployeeName
FROM [dbo].[...
2
votes
1
answer
14k
views
How to select a subset from a query result
I have a query which calculates the Time Difference and Distance Between the Next and Previous Row:
SELECT * FROM (
SELECT
iVehicleMonitoringId AS PreviousId,
...
8
votes
1
answer
1k
views
How can I get the hierarchical values from the below query?
I have a table named Category which has a column named CategoryID. There is a referencing column in the same table called fParentCategoryID.
I need to get all the category IDs and their subcategory ...
3
votes
1
answer
2k
views
How to union four different tables
I have two tables whereby both of them use sub queries. These two tables are combined by using UNION ALL.
I have two other tables that only uses a WHERE clause and both of these are combined using ...
-1
votes
1
answer
191
views
on every row on SELECT Query must lookup to other table
I'm working on Login/Logout System and I'm facing this problem regarding on SELECT Query. I have 2 tables namely dtr_tbl and shift_tbl. In dtr_tbl are the logs of the user(login/logout time details) ...
2
votes
1
answer
882
views
Update only the oldest entry in a table with foreign key criteria
I'm working on a forum website.
What I am trying to do is updating the thread Title and Content (first post), which resides in different tables - "Threads" and "Posts".
"Threads"
"Posts"
I'm not ...