Viewing 15 posts - 661 through 675 (of 3,500 total)
I think this works... <g> Standard pattern is to do the TOP N inside the CROSS APPLY, and join the Cross Apply to the outer query. (that's what the tt.Month...
August 2, 2020 at 1:45 am
This looks like it works:
SELECT DISTINCT t.Company,sales.[Month], sales.Sales
FROM TestTable t
CROSS APPLY (SELECT TOP 5 *
FROM [TestTable] t2
WHERE t.Company = t2.Company
ORDER BY t2.Sales DESC) sales
ORDER BY t.Company, sales.Sales...
August 2, 2020 at 12:17 am
Oh, I see now... how about something like this:
CREATE TABLE Employee (
EmployeeKey INT IDENTITY PRIMARY KEY,
FirstNameVARCHAR(20) NOT NULL,
LastNameVARCHAR(20) NOT NULL,
ShiftNo TINYINT NOT NULL
);
-- both WelderID and OperatorID...
August 1, 2020 at 1:05 am
Well, I meant joining to that table twice and returning the two different employee names...
TB_EMP.EMP_INT AS "WELDER",
TB_EMP.EMP_INT AS "OPERATOR",
Oh wait... can't do that... because that's only one column in EMP...
August 1, 2020 at 12:22 am
Store the dates as datetime, not VARCHAR. Then you can just use DATEDIFF(minute,startdate, enddate)
Otherwise you have to cast the VARCHAR columns, and that'll cause the query to be really slow...
July 31, 2020 at 6:05 pm
Looks like you need two instances of TB_EMP to join on the welder key and another to join on the Operator key.
July 31, 2020 at 6:03 pm
Are you trying to create an aging query, so that each invoice is "binned" by age, which is determined by [DocDate]? (the usual is something like "less than 30 days",...
July 29, 2020 at 3:00 pm
Just to see if I could do it, I wrote some code to do the testing for me... <g>
I shamelessly stole Phil's checking code.... Seems to work, though.
July 22, 2020 at 6:34 pm
Steve,
Since it's only looking at column names and not rows of data, it seems this could be done easily with a little bit of dynamic SQL (just get a list...
July 22, 2020 at 4:22 pm
Maybe this and use it as a cursor so I can create the columns that way?
use tempdb;
GO
IF OBJECT_ID('tempdb..#Test2') IS NOT NULL DROP TABLE #Test2
CREATE TABLE #Test2
(A int,...
July 22, 2020 at 2:55 pm
That many points and no consumable data?
SvcAcct is used on different ServerNames
SELECT ServiceAccount
FROM Accounts a INNER JOIN Servers s ON a.ServerID = s.ServerID
GROUP BY ServiceAccount
HAVING COUNT(*)>1
July 22, 2020 at 2:37 pm
Oh, so it's not an "out of the box" thing. I was watching one of Brent Ozar's videos on SSMS, and I thought it was. Thanks! Might have to splurge...
That's...
July 22, 2020 at 2:22 pm
I believe that the editor window colors are a windows user specific setting, not a SQL session specific setting.
=(
Drat. So at least I might not be as dumb as I...
July 21, 2020 at 10:33 pm
DECLARE @p_start_date DATETIME = CAST('2017-12-01 00:00:00' AS DATETIME);
DECLARE @p_end_date DATETIME = CAST('2017-12-31 00:00:00' AS DATETIME);
SELECT
DATEDIFF( HOUR
, @p_start_date
, @p_end_date
); July 21, 2020 at 6:11 pm
Viewing 15 posts - 661 through 675 (of 3,500 total)