Viewing 15 posts - 6,481 through 6,495 (of 8,731 total)
You should use UNPIVOT or maybe the CROSS APPLY approach.
http://www.sqlservercentral.com/articles/CROSS+APPLY+VALUES+UNPIVOT/91234/
May 14, 2014 at 9:01 am
You seem to have "Work" tables and "History" tables and you use UNION between them. You must realize that UNION and UNION ALL work slightly different. UNION will return a...
May 14, 2014 at 8:57 am
Scott,
Your query returns a different result. That might be what the OP was looking or it might not. I'm not sure. I agree that it would be a better...
May 14, 2014 at 8:40 am
Removing NOLOCK won't give inaccurate results. Adding it might. You can read more in this article http://blogs.msdn.com/b/davidlean/archive/2009/04/06/sql-server-nolock-hint-other-poor-ideas.aspx and you could google for other examples on why it's a bad idea.
I...
May 13, 2014 at 6:13 pm
Wow, that's a lot of code to even try to imagine what's going on. Remember that we don't know how do your tables and data look like.
The only tip...
May 13, 2014 at 5:37 pm
That means that your database doesn't have a table (or view) called events. Check that you're running the query in the correct db and that the table exists.
May 13, 2014 at 9:08 am
I wouldn't use the cross apply, but it's just a personal preference.
It should be interpreted the same way as Chris M's query.
SELECT MeteriD,
Reading = SUM(Reading),
DateByHour = DATEADD(hour,DATEDIFF(hour,0, ReadingDate),0)
FROM...
May 13, 2014 at 8:42 am
You're welcome. Thank you for the feedback.
I hope that you understand how the solution works. If not, feel free to ask any questions that you have.
May 13, 2014 at 8:20 am
You could append enough zeros and use a RIGHT() function when integrating the n value.
RIGHT( '0000' + CAST(N as varchar), 4)
Here's a great explanation on how the tally table (CTE...
May 12, 2014 at 1:44 pm
The query you posted shouldn't give an error on a subquery returning more than 1 value. However, we can't see the stored procedure. Your error might be in there.
I agree...
May 12, 2014 at 1:14 pm
The problem is that you only have a single value with your variables and you need more than one.
Using a JOIN instead of the variables, you can get it working.
SELECT...
May 12, 2014 at 8:28 am
This might not be the best option for performance (as I haven't done real performance testing) but it's quite simple.
SELECT c.IdCompany,
c.CompanyName,
ISNULL( p.CompanyCode,...
May 12, 2014 at 7:57 am
Your query looks just like mine but using a while loop instead of a single operation. Why would you do that.
Without DDL and sample data, I can't be sure why...
May 11, 2014 at 11:10 am
When you're testing one query against another, they're of great help. You'll be running both queries under the same circumstances. Of course, queries will be faster if you have the...
May 11, 2014 at 11:05 am
Would it be a recurrent process? or a single-time replica?
May 9, 2014 at 4:44 pm
Viewing 15 posts - 6,481 through 6,495 (of 8,731 total)