Viewing 15 posts - 211 through 225 (of 4,085 total)
Try a CROSS APPLY with a TOP(1) instead of a join.
CREATE TABLE #Details
(
ID INT,
ColumnA INT,
ColumnB INT
)
CREATE TABLE #SubDetails
(
A INT,
B INT
)
INSERT INTO #SubDetails (A, B)
VALUES (1, NULL), (2,...
J. Drew Allen
Business Intelligence Analyst
Philadelphia, PA
May 19, 2022 at 6:57 pm
Instead of using the apply approach you can also try a reworked query, which works wth the minimal test data you provided:
declare @v_po_history table (
...
J. Drew Allen
Business Intelligence Analyst
Philadelphia, PA
May 12, 2022 at 5:07 pm
Your WHERE clause is evaluated for EACH RECORD. A single record cannot both be equal to 1000 and 2000. You need a query that looks at multiple records. Piet's is...
J. Drew Allen
Business Intelligence Analyst
Philadelphia, PA
May 6, 2022 at 2:12 pm
Your Excel formula is wrong. Look at some simple examples.
J. Drew Allen
Business Intelligence Analyst
Philadelphia, PA
May 6, 2022 at 1:49 pm
Your Excel formula doesn't make sense to me. For one thing, your Excel data isn't sorted, so your value for January is based on the value for April. For another...
J. Drew Allen
Business Intelligence Analyst
Philadelphia, PA
May 5, 2022 at 6:30 pm
A recursive CTE is likely to be your best option. Why are you excluding CTEs?
J. Drew Allen
Business Intelligence Analyst
Philadelphia, PA
May 5, 2022 at 3:27 pm
Your sample data has no relation to your expected output. How do you expect people to get from the sample data to your expected output if they are completely disconnected...
J. Drew Allen
Business Intelligence Analyst
Philadelphia, PA
May 5, 2022 at 3:04 pm
I suggest that you don't open multiple threads for the same topic. Responses here: https://www.sqlservercentral.com/forums/topic/max-date-order-by-status
J. Drew Allen
Business Intelligence Analyst
Philadelphia, PA
April 19, 2022 at 9:06 pm
The purpose of the MIN/MAX is to assign a unique ID to each group. It doesn't matter if the IDs are ordered or not, it's just a way of picking...
J. Drew Allen
Business Intelligence Analyst
Philadelphia, PA
April 6, 2022 at 3:25 pm
You haven't given expected results, but this at least groups the records you wanted together. The approach I took was to find the minimum booking id for each event (pick/drop)...
J. Drew Allen
Business Intelligence Analyst
Philadelphia, PA
April 5, 2022 at 8:55 pm
There's the LAST_VALUE function. In order to return the "last value" (when the set is ordered by: OVER (ORDER BY ...)) across the entire window of rows (in this...
J. Drew Allen
Business Intelligence Analyst
Philadelphia, PA
January 28, 2021 at 6:45 pm
CROSS APPLY requires reading the same table twice. You can do this by only reading the table once. It involves concatenating the order fields and the value field together (possibly...
J. Drew Allen
Business Intelligence Analyst
Philadelphia, PA
January 28, 2021 at 6:13 pm
Look at the LEAD() function--LAG() would also work.
When posting sample data, you should use the {;} insert/edit code sample button to insert the script directly in your question instead of...
J. Drew Allen
Business Intelligence Analyst
Philadelphia, PA
January 26, 2021 at 5:13 pm
UNION ALL didn't achieve what I am looking for. Please see attachment. There are two warehouses, S0 and LU. On the first line, we can see that activity...
J. Drew Allen
Business Intelligence Analyst
Philadelphia, PA
July 10, 2020 at 3:19 pm
UNION does an automatic DISTINCT. Try using UNION ALL instead. If that doesn't answer your question, you'll need to provide sample data and expected results. The data should be provided...
J. Drew Allen
Business Intelligence Analyst
Philadelphia, PA
July 9, 2020 at 4:52 pm
Viewing 15 posts - 211 through 225 (of 4,085 total)