Need to do an SQL select statement in Classic ASP for a variable

I need to replace a session variable with the results of an SQL statement
that statement essentially is:
SELECT EmailAddress FROM USERS WHERE UserID=session(userid)"

Open in new window

My code is currently:
dim paypalnew as string = "SELECT EmailAddress FROM USERS WHERE UserID='"&session(userid)&"'"	

Open in new window

However I am getting an error at "as"

I tried doing paypalnew=thestring but it put it as straight text instead of being a SQL Statement.

This is my first real programming project, so i know that i am probably just missing some basics, but finding resources for classic ASP is very tough :/
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Paul JacksonSoftware EngineerCommented:
There are no datatypes in VBA other then variants so all variables are just defined like

Dim myVariableName

and to set a value to it :

Set myVariableName = 'whatever'

so your code would become :

dim paypalnew 
set paypalnew = "SELECT EmailAddress FROM USERS WHERE UserID='"&session(userid)&"'"	

Open in new window

However you code will not achieve you desired result (as I understand it) of populating the session variable with the result of the query it will just populate it with the text.
dashifireAuthor Commented:
that's what i need to know how to do, get the variable
Paul JacksonSoftware EngineerCommented:
Here is a good asp resource :

Here is a resource for learning about how to use ADO for connecting to databases using asp :
CompTIA Cloud+

The CompTIA Cloud+ Basic training course will teach you about cloud concepts and models, data storage, networking, and network infrastructure.

Paul JacksonSoftware EngineerCommented:
What kind of database are you using?
dashifireAuthor Commented:
dashifireAuthor Commented:
sweet resources btw.
Paul JacksonSoftware EngineerCommented:
Another nice tutorial here on how to use ado with asp to connect to a sql server database :
In VB you do not have to dim your vars unless you have Option Explicit ON. Personally I never use it. I just pay attention to my vars and make sure I don't use the same name twice.

Not sure how much code you have versus what you're showing us, but you're missing some  basics so here's how I would do it...

SQL_Conn_STRING = "Driver={SQL Server};Server=MyServerName;Database=MyDBName;uid=MyUsername;pwd=MyPassword"
Set Con = Server.CreateObject("Adodb.Connection")
Con.Open SQL_Conn_STRING

set rs  = Con.Execute("SELECT Top1 EmailAddress FROM USERS WHERE UserID='"&session("userid")&"'")	
If NOT rs.EOF then
      paypalnew = Trim(rs("EmailAddress"))
      ' No user found with this UserID
End if

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
dashifireAuthor Commented:
Thanks when I get a shot next I will try this. I do have option explicit on though, not my idea, but working with it anyway.
Then just make sure to dim all your variables first before you use them.
dashifireAuthor Commented:
That was perfect, the tutorials are terrific, but they don't tell me what is a variable and i was getting confused. I got it up and running now, so it is all good! Thanks Guys!
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.