|
Pie is good. I like pie.
Deja View - the feeling that you've seen this post before.
|
|
|
|
|
I agree with Pete, I like Pie too. Preferrably Apple.
|
|
|
|
|
These two queries return the same result set(different results as different fields).
A colleague wrote the first query and I wrote the second.
Now I think the first one looks just plain ugly, however the execution plan is not too dissimilar to the second query, which I wrote.
Is there any rationality to my response of Urghhhh?
My colleague's version:
select
sat.salesnumber,
pjq.pickjobnumber
from
(select salesnumber, rownumber, invoiceaccount
from salestable
where dataset = 'wtl'
and ltrim(salesnumber) = '331299') as sat
join
(select * from
pickjobtrans) as pjt
on sat.rownumber = pjt.picksalesrecid
join
(select * from
pickjobqueue) as pjq
on pjt.pickjobnumber = pjq.pickjobnumber
group by sat.salesnumber, pjq.pickjobnumber
</code>
My version:
select distinct pjq.accountnumber,pjq.status
from pickjobqueue pjq
right join pickjobtrans pjt
on pjq.pickjobnumber = pjt.pickjobnumber
right join salestable sal
on pjt.picksalesrecid = sal.rownumber
where ltrim(sal.salesnumber) = '331299'
</code>
You always pass failure on the way to success.
|
|
|
|
|
The one that runs faster
|
|
|
|
|
I think having a column called salesnumber which is actually a char datatype is a bit of a db design coding horror too
|
|
|
|
|
Yes - it's a Mircosoft XAL database.
It would make more sense space-wise as well as a varchar, in this case, will take more space than an int type which only takes 4 bytes.
Microsoft bought the database from Navision who bought it from Daamgard before it was a SQL database.
Let that be a warning to database design - get it wrong at the beginning and you can be left with problems for the life of the product.
You always pass failure on the way to success.
|
|
|
|
|
I am not a fan of SELECT *, It returns too much data, taking up resources along the way. That being said, my only other complaint is the lack of formatting, but that is just code style. I find the extra formatting makes it easier to find the part I want to work on.
SELECT DISTINCT pjq.accountnumber,
pjq.status
FROM pickjobqueue pjq
RIGHT JOIN pickjobtrans pjt
ON (pjq.pickjobnumber = pjt.pickjobnumber)
RIGHT JOIN salestable sal
ON (pjt.picksalesrecid = sal.rownumber)
WHERE LTRIM(sal.salesnumber) = '331299'
Hogan
|
|
|
|
|
I take your point on formatting.
snorkie wrote: I am not a fan of SELECT *, It returns too much data, taking up resources along the way
I am in the same camp as you here, however when I looked at the execution plan both queries have very similar execution plans.
In the end neither was faster.
My position is more that it just looks lazy using those select* statements.
I also find a beauty in being able to write code that is short and concise.
Maybe I am being pedantic and need to let go...
-- modified at 15:28 Tuesday 6th November, 2007
You always pass failure on the way to success.
|
|
|
|
|
GuyThiebaut wrote: I am in the same camp as you here, however when I looked at the execution plan both queries have very similar execution plans.
In the end neither was faster.
To a large extent, the execution plan is immaterial here. What matters more is the amount of data that is returned over the network. If you only need one column, why put more load on what may already be a busy network by returning 20?
Deja View - the feeling that you've seen this post before.
|
|
|
|
|
Select *....just say no. It is a lazy approach and as Pete points out you can end up creating a lot of network traffic for no benefit.
|
|
|
|
|
not to mention the possibility of some adding a big field to the end of the table (blob for instance) and your code suddenly grinding to a halt.
I won't use select * even if i want every field as you have no idea what changes may come later
Russ
|
|
|
|
|
snorkie wrote: I am not a fan of SELECT *,
I support you. Even in the case of selecting all the columns of the table (only remote combinations of applications), I prefer having them enumerated instead of *. I feel it is more readable and friendly too not to mention about the significant gains in terms of performance.
For that matter, I think, even C# takes that stand. Like Java, where java.lang.* no longer works for namespace inclusions in managed code. Isn't it?
Vasudevan Deepak Kumar
Personal Homepage
Tech Gossips
Yesterday is a canceled check. Tomorrow is a promissory note. Today is the ready cash. USE IT.
|
|
|
|
|
Spent about 45 min trying to figure out why title was lost after returning at the end of the function .
DoSomething(Text *text_store, int seven)<br />
{<br />
char *text;<br />
text = (char*) malloc(sizeof(char) * seven);<br />
text_store.title = text;<br />
free(text);<br />
} <br />
-- modified at 15:05 Monday 5th November, 2007
And yes text_store.title is a pointer
this thing looks like it was written by an epileptic ferret
Dave Kreskowiak
|
|
|
|
|
Is your post missing some content?
Peace!
-=- James Please rate this message - let me know if I helped or not!<HR> If you think it costs a lot to do it right, just wait until you find out how much it costs to do it wrong! Avoid driving a vehicle taller than you and remember that Professional Driver on Closed Course does not mean your Dumb Ass on a Public Road! See DeleteFXPFiles
|
|
|
|
|
I think thats what the // more code is for
xacc.ide
The rule of three: "The first time you notice something that might repeat, don't generalize it. The second time the situation occurs, develop in a similar fashion -- possibly even copy/paste -- but don't generalize yet. On the third time, look to generalize the approach."
|
|
|
|
|
The post originally showed no code, then was modified (after my post).
Peace!
-=- James Please rate this message - let me know if I helped or not!<HR> If you think it costs a lot to do it right, just wait until you find out how much it costs to do it wrong! Avoid driving a vehicle taller than you and remember that Professional Driver on Closed Course does not mean your Dumb Ass on a Public Road! See DeleteFXPFiles
|
|
|
|
|
Well if the type of 'text_store.title' is pointer, then you are freeing the memory that it points to. That will usually create havoc.
|
|
|
|
|
Make title a CString and it should work fine.
Greetings from Germany
|
|
|
|
|
Uhh....loooks like you've forgotten 1 extra for NUL terminated char...
text = (char*)malloc(sizeof(char) * (seven + 1));
And also...check for NULL if this fails...my c skills are a bit rusty so excuse if I trip up, from what I can remember this nice terse statement which was favourite of mine..
if (!(text = (char*)malloc(sizeof(char) * (seven+1)))){
...mem is gud...
}else{
...phffft...
}
this is a nice lil exercise since I used to program in C professionally, then switched over to C# cos the skillset was dwindling in the IT sector here in Ireland... not sure why you'd free the pointer though...I think that you'll have garbage in text_store.title...I could be way off here on this...
Take care,
Tom
#define STOOPID
#if STOOPID
Console.WriteLine("I'm stoopid!");
#endif
|
|
|
|
|
I just spent an hour trying to think why the process didn't work.
for(int nindex = MIN_VAL; nindex <= MAX_VAL; nindex++);<br />
{<br />
}
Maybe everyone has these kind of moments.
|
|
|
|
|
Llasus wrote: Maybe everyone has these kind of moments.
I had that exact moment about 15 years ago in a C++ app. It took me half the day trying to figure out why the loop executed once and only once.
Marc
|
|
|
|
|
Marc Clifton wrote: It took me half ...
That's, uh, quite a way to show superiority...;P
|
|
|
|
|
Me, too. I think it's a rite of passage for C programmers.
|
|
|
|
|
Christopher Duncan wrote: Me, too. I think it's a rite of passage for C programmers.
Yep right along with while (someBool = TRUE)
--
If you view money as inherently evil, I view it as my duty to assist in making you more virtuous.
|
|
|
|
|
The compiler will help you if you are good enough to use the loop index in the loop body...
Luc Pattyn [Forum Guidelines] [My Articles]
this months tips:
- use PRE tags to preserve formatting when showing multi-line code snippets
- before you ask a question here, search CodeProject, then Google
|
|
|
|