Remember, in classic ASP, all variables are considered "variant", so when it comes to SQL, it does not matter if X = 1 or Y = "1"
However, this *is* important in the ASP code (but not SQL code)
Code:
In ASP,
If X = 1 then... results in TRUE
If X = "1" then... results in FALSE
and
If Y = 1 then... results in FALSE
If Y = "1" then... results in TRUE
However, When you are sending a select statement to SQL SERVER, it *all* gets sent as a string.
Asssume the following table, PERSON, in Sql Server.
AGE is INT
NAME is char(50)
In ASP, you can do:
Code:
strSQL = "Select * from PERSON, Where AGE=" & X
or
strSQL = "Select * from PERSON, Where AGE=" & Y
Notice that there are *no* quotes around X or Y. Quotes imply that it is a string. AGE is an INT, so it expects an int. In both cases, SQL will intepret this as
Select * from PERSON, Where AGE = 1
This is also allowed:
Code:
strSQL = "Select * from PERSON, Where NAME=" & "'" & X & "'"
or
strSQL = "Select * from PERSON, Where NAME=" & "'" & Y & "'"
Notice that I *do* have single quotes around X and Y. Becuase NAME is a char() and expects a string. In both cases, SQL will intepret this as
Select * from PERSON, Where NAME= '1'
Please also note that in SQL Server, strings
must be in single quotes.
Last Example:
Code:
Both of these will give you a SQL Error:
strSQL = "Select * from PERSON, Where AGE=" & "'" & X & "'"
strSQL = "Select * from PERSON, Where NAME=" & X
In example 1, AGE is expecting an INT, so by sending it the string '1', it causes an error.
In example 2, NAME is expecting a CHAR, so by send it the numeric 1, it causes an error.
~Le