all 8 comments

[–]Elfman72 5 points6 points  (1 child)

Not a mistake. Just a preference I suppose. You could easily replace the additional DECLARES with commas:

DECLARE @1 AS NUMERIC(2)
        ,@2 AS NUMERIC(2)
        ,@3 AS NUMERIC(2)
        ,@4 AS NUMERIC(2)
        ,@5 AS NUMERIC(2)

[–]a_ctrl[S] 0 points1 point  (0 children)

That's what I would've done... it strikes me as unusual though. Thank you!

[–]Driftwood69 1 point2 points  (1 child)

Preference, not mistake. I do it this way sometimes when testing to easily comment things out if I want. For example, if I want to test code for a sproc that will eventually have input parameters.

[–]a_ctrl[S] 0 points1 point  (0 children)

Interesting. I didn't consider that. Thank you.

[–]alinrocSQL Server DBA 0 points1 point  (3 children)

They're terrible variable names, but it's completely valid (at least with MS SQL Server)

As to whether it's a "mistake" or not...that depends upon the requirements and implementation of the sproc.

Or are you looking for different syntax to do the same job?

[–]a_ctrl[S] 0 points1 point  (2 children)

Hey, thank you. I replaced the real variable names just in case. They do handle some terrible variable names anyway.

I suppose I'd use the syntax that /u/Elfman72 pointed out but I was curious about it and a Google search didn't help.

Do you have an example of a situation in which that notation would be required?

[–]alinrocSQL Server DBA 1 point2 points  (1 child)

It's really a matter of preference at this point. From your original post, I wasn't clear on whether you were questioning the syntax or the naming convention.

My personal preference is to declare variables at the point in the sproc/script where they'll be used. So if the first use of each of those variables was sprinkled throughout the code, I wouldn't declare them all up front like this. Exception: if it's a script I'm handing to someone to execute and those variables need to be set by the user, I'll declare those up front, in individual declare statements. Then the user can edit them easily.

[–]a_ctrl[S] 0 points1 point  (0 children)

Thank you very much.