Viewing 15 posts - 631 through 645 (of 3,480 total)
Dynamic SQL?
Create one variable to hold the static part of the INSERT statement, and then use the cursor to create the dynamic part, and use sp_executesql to execute the whole...
August 13, 2020 at 6:55 am
So what happens if you create your temporary table and then do something like
INSERT INTO #TempTable(col1)
SELECT * FROM OPENROWSET('MSDASQL','Driver={MySQL ODBC 5.3 ANSI Driver};server=xxxxxxx;userid=xxxxx;pwd=;database=xxxxxx;port=xxxxx;','SELECT col1 from table1')
August 13, 2020 at 4:07 am
use a stored procedure, and create a variable in it, say @Total and ...
SELECT @AllSalesAmount = 1.0 * SUM(Sales[Amount]);
Then divide your sum by that in your pivot.
August 7, 2020 at 9:52 am
Do you mean something like this?
SELECT *
FROM duplicateSample ds2
WHERE ds2.RIN IN (SELECT RIN
FROM duplicateSample ds1
WHERE rowNum = 2 );
August 6, 2020 at 5:27 pm
The most likely reason you're having a hard time is that you're missing a Calendar table. I borrowed some code from Dwain Camps for it. I ran this part...
August 5, 2020 at 4:45 am
Don't get into the habit of using implicit casting. If you're joining on two columns with different data types, one entire column has to be cast, and if you have...
August 5, 2020 at 3:20 am
It's not that CAST doesn't work, it's that it's expensive, especially if you use it in a crazy place like a join.
August 5, 2020 at 12:41 am
It's easier than that.
select * from tblTest
where TestNumber = '20012';
August 4, 2020 at 11:58 pm
You're welcome... sorry it took me a bit to actually understand the question.
August 2, 2020 at 1:56 pm
(sorry, my internet is freaking out... double post).
August 2, 2020 at 1:47 am
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
Viewing 15 posts - 631 through 645 (of 3,480 total)