Viewing 15 posts - 3,511 through 3,525 (of 10,143 total)
Check your table aliases:
SELECT s.state_name
, COUNT(DISTINCT DUPS.PermitNumber) AS NumOfDupPermits
, SUM(DistinctPermits) AS DistinctPermits
FROM States S
CROSS APPLY (
SELECT w.StateID, COUNT(*) as DistinctPermits
FROM Permit P
INNER JOIN Well W1 ON P.WellID...
For fast, accurate and documented assistance in answering your questions, please read this article.
Understanding and using APPLY, (I) and (II) Paul White
Hidden RBAR: Triangular Joins / The "Numbers" or "Tally" Table: What it is and how it replaces a loop Jeff Moden
March 21, 2014 at 3:28 am
rlsublime (3/20/2014)
(Select sum(NVL(sh_productivehours,0))
...
For fast, accurate and documented assistance in answering your questions, please read this article.
Understanding and using APPLY, (I) and (II) Paul White
Hidden RBAR: Triangular Joins / The "Numbers" or "Tally" Table: What it is and how it replaces a loop Jeff Moden
March 21, 2014 at 2:51 am
Here's a sandpit version very similar to what you currently have. The only downside is the ugly aggregate - but it's a very simple ugly aggregate. I guess it depends...
For fast, accurate and documented assistance in answering your questions, please read this article.
Understanding and using APPLY, (I) and (II) Paul White
Hidden RBAR: Triangular Joins / The "Numbers" or "Tally" Table: What it is and how it replaces a loop Jeff Moden
March 20, 2014 at 9:56 am
Can you augment the sample table in my last post to account for your observations? Thanks.
For fast, accurate and documented assistance in answering your questions, please read this article.
Understanding and using APPLY, (I) and (II) Paul White
Hidden RBAR: Triangular Joins / The "Numbers" or "Tally" Table: What it is and how it replaces a loop Jeff Moden
March 20, 2014 at 9:04 am
SQL Server will apply the filter and the conversion in whichever order results in the lowest cost - and in this case, the order chosen is breaking your query. Here's...
For fast, accurate and documented assistance in answering your questions, please read this article.
Understanding and using APPLY, (I) and (II) Paul White
Hidden RBAR: Triangular Joins / The "Numbers" or "Tally" Table: What it is and how it replaces a loop Jeff Moden
March 20, 2014 at 7:50 am
You're welcome, thanks for the feedback.
For fast, accurate and documented assistance in answering your questions, please read this article.
Understanding and using APPLY, (I) and (II) Paul White
Hidden RBAR: Triangular Joins / The "Numbers" or "Tally" Table: What it is and how it replaces a loop Jeff Moden
March 20, 2014 at 7:22 am
There are loads of ways of doing this. Here are two.
drop Table #Sample
Create Table #Sample (ID int not null primary key, RefID int , SeqNo int , Name varchar(10) ...
For fast, accurate and documented assistance in answering your questions, please read this article.
Understanding and using APPLY, (I) and (II) Paul White
Hidden RBAR: Triangular Joins / The "Numbers" or "Tally" Table: What it is and how it replaces a loop Jeff Moden
March 20, 2014 at 4:46 am
The numeric test and the cast to bigint have to occur together and in the correct order.
CREATE VIEW ChildEmployees
AS
SELECT x.EmpID
FROM MasterEmployees
CROSS APPLY (
SELECT EmpiD CASE
WHEN ISNUMERIC(EmpID) =...
For fast, accurate and documented assistance in answering your questions, please read this article.
Understanding and using APPLY, (I) and (II) Paul White
Hidden RBAR: Triangular Joins / The "Numbers" or "Tally" Table: What it is and how it replaces a loop Jeff Moden
March 18, 2014 at 10:47 am
Here's a solution which will work with many values. First the UDF:
ALTER FUNCTION fn_BITWISE_OR
(
@col1 VARCHAR(3)
)
RETURNS VARCHAR(3)
AS
BEGIN
-- try row-wise
DECLARE @LastValue INT
SELECT @LastValue = 000
SELECT @LastValue = @LastValue | d.bit_flag
-- substitute...
For fast, accurate and documented assistance in answering your questions, please read this article.
Understanding and using APPLY, (I) and (II) Paul White
Hidden RBAR: Triangular Joins / The "Numbers" or "Tally" Table: What it is and how it replaces a loop Jeff Moden
March 18, 2014 at 10:10 am
joakim.fenno (3/18/2014)
CREATE TABLE my_table (col1 nvarchar(25) NULL, bit_flag nvarchar(3) NULL)
INSERT INTO my_table VALUES('A', '100'), ('A', '001'),('B', '010'),('A', '001');
expected output from query :
A 101
B 011
The bit_flag column contains 12 flag (and...
For fast, accurate and documented assistance in answering your questions, please read this article.
Understanding and using APPLY, (I) and (II) Paul White
Hidden RBAR: Triangular Joins / The "Numbers" or "Tally" Table: What it is and how it replaces a loop Jeff Moden
March 18, 2014 at 9:46 am
Although just about every reference on the first page returned by Google specifies two operands, the TSQL BITWISE OR actually works with a chain like this:
-- on a single...
For fast, accurate and documented assistance in answering your questions, please read this article.
Understanding and using APPLY, (I) and (II) Paul White
Hidden RBAR: Triangular Joins / The "Numbers" or "Tally" Table: What it is and how it replaces a loop Jeff Moden
March 18, 2014 at 9:36 am
joakim.fenno (3/18/2014)
ChrisM@Work (3/18/2014)
joakim.fenno (3/18/2014)
ChrisM@Work (3/18/2014)
If you can guarantee that your aggregate function would always and only ever generate the two values required by BITWISE OR, then you will find it...
For fast, accurate and documented assistance in answering your questions, please read this article.
Understanding and using APPLY, (I) and (II) Paul White
Hidden RBAR: Triangular Joins / The "Numbers" or "Tally" Table: What it is and how it replaces a loop Jeff Moden
March 18, 2014 at 9:25 am
joakim.fenno (3/18/2014)
ChrisM@Work (3/18/2014)
If you can guarantee that your aggregate function would always and only ever generate the two values required by BITWISE OR, then you will find it far far...
For fast, accurate and documented assistance in answering your questions, please read this article.
Understanding and using APPLY, (I) and (II) Paul White
Hidden RBAR: Triangular Joins / The "Numbers" or "Tally" Table: What it is and how it replaces a loop Jeff Moden
March 18, 2014 at 9:12 am
joakim.fenno (3/18/2014)
But the function needs to work as an aggregate function.
I have to be able to execute...
For fast, accurate and documented assistance in answering your questions, please read this article.
Understanding and using APPLY, (I) and (II) Paul White
Hidden RBAR: Triangular Joins / The "Numbers" or "Tally" Table: What it is and how it replaces a loop Jeff Moden
March 18, 2014 at 8:53 am
karthik babu (3/18/2014)
as early as possible.. since its EOD today we have 12+ hrs 🙂
How about pasting the assignment here so we don't have to guess what you're trying to...
For fast, accurate and documented assistance in answering your questions, please read this article.
Understanding and using APPLY, (I) and (II) Paul White
Hidden RBAR: Triangular Joins / The "Numbers" or "Tally" Table: What it is and how it replaces a loop Jeff Moden
March 18, 2014 at 8:06 am
Viewing 15 posts - 3,511 through 3,525 (of 10,143 total)