Journal Marxist Hacker 42's Journal: When did I become an incompetent at TSQL? 32
What is wrong with this code? It's like I can have the inner loop execute, or the outer loop execute, but not both.
DECLARE @RC int
DECLARE @BatchMatch varchar(40)
Declare @mcount int
Declare @dcount int
Set @mcount=1
Set @dcount=1
While @mcount <13
Begin
while @dcount<32
Begin
Set @BatchMatch=Right('00'+Convert(varchar(2), @mcount),2) + Right('00' + Convert(varchar(2),@dcount),2)
Print @BatchMatch
Set @dcount=@dcount+1
End
Set @mcount=@mcount +1
End
PS, no I don't care that all months don't have 31 days, but I must cover months that do.
-------------------------------------------
Update- failed to reset the inner loop counter, that's what.
Re: (Score:2)
Specifically the innermost loop in the nesting. Outer loop is counting months, inner loop is counting days, and the set statement is combining the two into a string to pass to a different routine.
Re: (Score:2)
Final answer was to add a "Set @dcount=1" after the END
Like domain aggreggates in MS Access (Score:2)
You may need to ponder rephrasing your requirement to store intermediate results in a temp table?
Re: (Score:1)
Three out of three WTF's for that post. Jeebus.
@MH42: None of us spotted the boo-boo, so don't feel like you're slipping too badly.
Re: (Score:2)
Re: (Score:2)
They have, but not enough.
Re: (Score:1)
It works just fine. You're not supposed to write your application logic in it. (I keep saying to the people I work with.)
Re: (Score:2)
I have seen people re-invent the database engine in Java, though.
Re: (Score:1)
It seems you'd really have to hate yourself to try.
Or just not know any better. Because they don't care to know any better.
I have seen people re-invent the database engine in Java, though.
Because they didn't want to learn SQL. Unfortunately many Java devs are like C# devs, in that they're modern versions of VB* devs.
*Where I went to school, there was the CS program taught out of the school of Engineering, and the MIS (Management Information Systems) program taught out of the school of Business. We did our programming projects in Pascal (and later C), they did theirs in BASIC. I'm interested in software engineering. M
Re: (Score:2)
Re: (Score:2)
Select ID from Table1 where ID Not in (Select ID from Table 2)
Re: (Score:2)
Re: (Score:1)
More roundabout than necessary, less effectively communicating intent.
Re: (Score:2)
Select Table1.ID from Table1 Left Join Table2 on Table1.ID=Table2.ID where Table2.ID is Null
Re: (Score:2)
Re: (Score:2)
Re: (Score:1)
The optimizer can't make less self-evident approaches understood as quickly tho.
Re: (Score:1)
I'd use EXCEPT. Correlated subqueries give me the performance heebie jeebies.
Re: (Score:2)
I'm showing my age as a programmer- like windowed functions (which I learned about in just the last year) this is the first that I've heard of Except and Intersect unions. They'd certainly run faster.
Re: (Score:1)
"windowed functions"
I'd be interested to know why you expended the mental energy to learn it (as someone who's only heard of it, but is particular about what I allocate precious brain cells to).
Re: (Score:2)
Main reason was for an Intel internal tool called SQL Pathfinder- which used windowing functions for a wide variety of reporting tasks with Oracle, SQL Lite, and SQL Server.
The main time they're useful is for when you need to group an aggregate by something other than the group by clause. You can even report multiple aggregates grouped in different ways in a single record in the dataset.
BTW (Score:2)
<ecode> tag is great for code. You don't even have to escape less than signs!
Re: (Score:2)
That's all well and dandy- and thank you, I'll remember that (and look it up, is it now a standard tag?). But where did slashdot hide my edit journal post link?
Re: (Score:2)
If you go to your journal list [slashdot.org] do you see a very dark gray gear on the very dark subject line on the journal next to the green "Journal" thing sticking out the side? (obviously not, but it's there. It's also right next to the very dark gray (x) icon to delete it, so clicking blindly is dangerous.) It's fancypants javascript so it may or may not work, it took a few seconds on mine to convert the subject and body fields to inputs I could change (I just tested it on mine, the "Preview" shows me the original
Re: (Score:2)
Nice, but the e-code tag still doesn't seem to work. I saved it anyway.
Re: (Score:2)
And then it did.....Dr. Moon, paging Dr. Moon....
Re: (Score:1)
Preview doesn't always work there. Try using this [slashdot.org]. Only this time, bookmark it :-)
Ballmer Peak (Score:2)
This [xkcd.com] is probably more accurate than most people like to believe.
Re: (Score:1)
The message to take from that is, *Don't program and drive*