Catch up on stories from the past week (and beyond) at the Slashdot story archive

 



Forgot your password?
typodupeerror
×
User Journal

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.

This discussion has been archived. No new comments can be posted.

When did I become an incompetent at TSQL?

Comments Filter:
  • The execution environment is only evaluating the function once, and memoizing the result.
    You may need to ponder rephrasing your requirement to store intermediate results in a temp table?
    • 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.

      • Unless they've changed that clunky old environment in the 5+ years since I worked with it, T-SQL just doesn't work like, say, Perl.
        • They have, but not enough.

        • It works just fine. You're not supposed to write your application logic in it. (I keep saying to the people I work with.)

          • It seems you'd really have to hate yourself to try.
            I have seen people re-invent the database engine in Java, though.
            • 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

              • "Problem: offer an example of a 'find unmatched' query."
                • Select ID from Table1 where ID Not in (Select ID from Table 2)

                • I'd use EXCEPT. Correlated subqueries give me the performance heebie jeebies.

                  • 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.

                    • "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).

                    • 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.

  • by Qzukk ( 229616 )

    <ecode> tag is great for code. You don't even have to escape less than signs!

    if (x < y) {
      spaces indent
    }

    • 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?

      • by Qzukk ( 229616 )

        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

  • This [xkcd.com] is probably more accurate than most people like to believe.

FORTRAN is not a flower but a weed -- it is hardy, occasionally blooms, and grows in every computer. -- A.J. Perlis

Working...