|
In SqlServer unless those were declared somewhere it would create a table vXXXXX for each statement, if you wanted an assignment it would just be SELECT vXXXX = XXXX from table. You can string as many of those together in one statement as you like afaik.
Please remember to rate helpful or unhelpful answers, it lets us and people reading the forums know if our answers are any good.
|
|
|
|
|
No, variables have "@" in front of them. For example:
DECLARE @SomeVariable int
SELECT @SomeVariable
A SELECT INTO statement copies one set of values into a new table (it creates the new table).
|
|
|
|
|
This is PL/SQL, not T-SQL. (Oracle, not SQL Server)
|
|
|
|
|
|
Hey! Where did you get my code?!! o_O
|
|
|
|
|
I know where this may actually be valid. If the customer table is a monster and you need to do multiple complex joins and filtering then dropping them into table vars may be valid, 9 of them does seem somewhat excessive. It would depend on the downstream requirement.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
Yes, but even if there are 9 variables, you don't need 9 different queries to populate them. I think that's the point of the OP.
Instead of:
SELECT X INTO vX FROM CUSTOMERS WHERE IDTYPE =linea;
SELECT Y INTO vY FROM CUSTOMERS WHERE IDTYPE =linea;
SELECT Z INTO vZ FROM CUSTOMERS WHERE IDTYPE =linea;
you can do:
SELECT X, Y, Z INTO vX, vY, vZ FROM CUSTOMERS WHERE IDTYPE =linea;
The selection criteria in this case are identical for all 9 variables, so you can fetch them all in one hit.
|
|
|
|
|
Find in code :
if (Area.GetValueOrDefault(-1) == -1)
{
return 0;
}
return Area;
It's lucky that Area is non negative.
|
|
|
|
|
bourdiitsme wrote: // Check the result of area to avoid a Nan in display
Why are you trying to avoid exhibiting my maternal Grandmother?
Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together.
|
|
|
|
|
Nobody wants to see your grandmother on display.
|
|
|
|
|
You have no idea how glad that makes me! I don't think she'd be too happy herself - she has been dead for years...
Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together.
|
|
|
|
|
I wonder if the code at some point had some different instructions, possibly logging, for the null and non-null cases?
|
|
|
|
|
It's just a little fix to get a value and not a Nan (french-glish comments! ). Why do simple ?
|
|
|
|
|
Just for your pleasure, I have opened a random VB 6 program from my archive to post some horror.
This is from a program which purpose was to teach user doing simple math tasks, that is multipying, dividing, adding and subtracting. Well it worked, but I still don't know a multiplication table by heart.
I suppose Command1 was a "Start" button. Of course, the same code was copied to a "Next task" button.
Private Sub Command1_Click()
x = InputBox("Enter a name or a nick:", "Name?!", nz)
If x = "" Then Exit Sub
nz = x
kon = False
Command3.Enabled = True
Command4.Enabled = True
dzial.Interval = Text4 * 1000
odp.Interval = Text5 * 1000
Label1 = ""
Label8 = ""
Label1.Visible = True
il = 0
oc = 6
' Combo2.AddItem "0 - First component (denary)"
' Combo2.AddItem "1 - Both components (denary)"
' Combo2.AddItem "2 - First component (hundredth)"
' Combo2.AddItem "3 - Both components (hundredth)" <== whatever that means... ;)
If Check1 = 1 Then
ul = Combo2.ListIndex
Else
ul = 124
End If
1:
Randomize
d1 = Int((Text2 + 1) * Rnd)
Randomize
d2 = Int((Text3 + 1) * Rnd)
Randomize
If Check2 = 1 Then
rd = Int((4) * Rnd + 1)
Else
rd = Int((2) * Rnd + 1)
End If
If d1 = 0 Or d2 = 0 Or rd < 1 Or d1 = d2 Or d1 = 1 Or d2 = 1 Or rd > 4 Then GoTo 1
Randomize
If ul = 0 Or ul = 1 Then
a = Int((9 + 1) * Rnd)
a = Left(a, 1)
c = Str(d1)
c = c & "." & Str(a)
d1 = CDbl(c)
End If
If ul = 1 Then
a = Int((9 + 1) * Rnd)
a = Left(a, 1)
c = Str(d2)
c = c & "." & Str(a)
d2 = CDbl(c)
End If
If ul = 2 Or ul = 3 Then
a = Int((99 + 1) * Rnd)
a = Left(a, 2)
c = Str(d1)
c = c & "." & Str(a)
d1 = CDbl(c)
End If
If ul = 3 Then
a = Int((99 + 1) * Rnd)
a = Left(a, 2)
c = Str(d2)
c = c & "." & Str(a)
d2 = CDbl(c)
End If
If rd = 1 Then
w = d1 * d2
Label1 = d1 & " times " & d2 & " =?"
ElseIf rd = 2 Then
w = d2
Label1 = d1 * d2 & " divided by " & d1 & " =?"
ElseIf rd = 3 Then
w = d1 + d2
Label1 = d1 & " add " & d2 & " =?"
ElseIf rd = 4 Then
w = d1 - d2
Label1 = d1 & " minus " & d2 & " =?"
End If
dzial.Enabled = True
odp.Enabled = True
Command4.Enabled = False
Frame1.Enabled = False
Text1.SetFocus
Text1.SelStart = 0
Text1.SelLength = Len(Text1)
Command2.Enabled = False
End Sub
A correct answer was stored in a global variable "w".
A user could even set adifficulty level!:
Private Sub Combo1_Click()
Select Case Combo1.Text
Case "Easy"
Text2 = 10
Text3 = 12
Text4 = 9
Text5 = 28
Text6 = 11
Check1 = 1
Combo2.ListIndex = 0
Case "Elementary"
Text2 = 9
Text3 = 9
Text4 = 3
Text5 = 20
Check1 = 0
Combo2.ListIndex = 0
Text6 = 14
Case "Medium"
Text2 = 13
Text3 = 14
Text4 = 14
Text5 = 35
Text6 = 15
Check1 = 1
Combo2.ListIndex = 1
Case "Hard"
Text2 = 15
Text3 = 15
Text4 = 30
Text5 = 50
Text6 = 16
Check1 = 1
Combo2.ListIndex = 2
Case "Impossible to finish"
Text2 = 18
Text3 = 19
Text4 = 60
Text5 = 60
Text6 = 20
Check1 = 1
Combo2.ListIndex = 3
End Select
End Sub
Greetings - Jacek
|
|
|
|
|
oh fat cannon!
Yes, this confirms my oppinion. VB6 is the language with the most chaotic code i have ever seen. It's really a language for small short-life stuff.
For those who never where in that situation:
Imagine if you have a project with code like this in this language, but with 100000 source code lines...
|
|
|
|
|
Umm ... seems to me that the major coding horror of the OP's snippet is not that it's written in VB6, but that none of the variables are given meaningful names, there's no structure, etc.
The same horror could just as easily have been written in C#, etc., and the only thing you'd see differently is {} instead of THEN ... ELSE ... ENDIF, a few () scattered around, and '||' instead of 'OR', etc.
Not that I'd go out of my way to find a VB (6, .Net or other) job, of course.
|
|
|
|
|
Chris Trelawny-Ross wrote: find a VB (6, .Net or other) job,
Some times they find you.
|
|
|
|
|
I'm sorry if I hurt you.
Greetings - Jacek
|
|
|
|
|
Not hurt in the slightest. No apology needed.
|
|
|
|
|
Bigdeak wrote: Yes, this confirms my oppinion. VB6 is the language with the most chaotic code i have ever seen. It's really a language for small short-life stuff.
For those who never where in that situation:
Imagine if you have a project with code like this in this language, but with 100000 source code lines...
VB6 isn't perfect, but it didn't come fitted with a gun that pops out of the screen that forces you to write crap code.
Today, the most chaotic code I see is in VB/ASP.Net apps. And most of it knocks anything I ever saw in VB6 out of the ballpark.
And yet with both VB6 and VB.Net you can write beautiful elegant code.
So, why is there so much crap code out there?
Well...you're right. It is VB's fault.
VB made it possible for non programmers to program. Which means it made it possible for bad programmers to program.
The fact is, you see so much bad code in VB and VB.Net precisely because they are both such incredibly well implemented development tools.
The language isn't the problem, it's the numpty between the keyboard and the chair (no offence to the OP).
You will always see the worst code in the development tools that most appeals to the masses.
And the same simple fact has always been true.
Good programmers write good code. Bad programmers write bad code.
Suggesting that the language has anything to do with it is like advising a Spanish poet to learn English because you can write better poems in English.
|
|
|
|
|
At least in English, the poems ryhme.
Chris Meech
I am Canadian. [heard in a local bar]
In theory there is no difference between theory and practice. In practice there is. [Yogi Berra]
|
|
|
|
|
Doesn't improve spelling much though, eh?
|
|
|
|
|
As in Spanish also I love my language
|
|
|
|
|
1. Option Explicit Off
2. On Error Goto Label37
3.
With Object.Its.So.Nested
(...)
abc = .Some.Property
(...)
End With
4. Global myVar As String = "magic"
5. someInteger = CInt(int1/int2) (divide operator on two ints gives... a double ).
6. Non-zero based arrays -- a fantastic source of confusion
7. Propagating null value in nullable boolean logic -- three-state logic? uhm? I won't be suprised if the next VB version would have a fuzzy logic implemented.
Not a problem with a language? I don't think so...
Greetings - Jacek
|
|
|
|
|
Jacek Gajek wrote: 1. Option Explicit Off
Yes this is horrible, almost as bad as JavaScript doing exactly the same, but with (until ECMAScript5) no equivalent of Option Explicit On.
Jacek Gajek wrote: 2. On Error Goto Label37
Quite horrible, but to blame VB for a fault in BASIC since the year dot is a bit unfair.
3. With/End With - OK, this is truly a mistake.
4. I don't like globals either, but most languages, particularly of that era, support them.
5. someInteger = CInt(int1/int2) (divide operator on two ints gives... a double).
Actually - thats pretty correct. Last time I checked 1/2 in mathematics was 0.5, not 0 or 1.
Ideally, a language can distinguish integer division and floating-point division, maybe with different operators, but this doesn't seem too horrible to me.
6. Yes, a terrible decision, and Option Base 0 just made things worse, as code in different modules can have different bases. I don't mind base 0 or 1, consistency is really important.
7. Not sure what you're referring to here, but if you mean null-propagation where nulls occur in boolean expressions (where null is an allowable result), that's the only option. Check the literature on Relational DB's (Codd et al.) for the justification.
Actually, Codd proposes 4-state logic (Yes,No,Maybe and Inapplicable, Maybe and Applicable).
These are not really boolean logic though, but VB, with typed variables (As Boolean) behaves correctly AFAIK.
It's not a great language, but most languages have points that are plain bad (JavaScript springs to mind heavily). Programmer's should be able to avoid features that cause problems - that's what they're paid for.
I've seen plenty of bad Javascript too - for basically the same reasons as VB.
Maybe we should just ban high-level languages
|
|
|
|