sql query problem in asp.net?

TattyMane

New member
I have a database connected to an asp.net web page. When I run this query:
"SELECT [Previous Amount] as Previous_Amount FROM [pensions]" it works fine. However, I want to apply a variable to the values that are being returned. The variable is stored in a session variable called My_CPI_session. I have tried all sorts of variations on the syntax:
"SELECT [Previous Amount] * " & My_CPI_session & "as Previous_Amount FROM [pensions]"
I get errors like 'the server tag is not well formed'.
I'd appreciate it if someone could let me know what I'm doing wrong. Thanks
clement: thanks, but that hasn't helped. The 'wildcard' is actually the multiplication symbol. I want to multipy the data I get from the database by my variable.
 
You may need to cast your host variable to a string representation, since you are concatenating strings together to build your SQL query. Also, make sure you have a leading space in "as Previous_Amount FROM [pensions]" so that the result is something like

SELECT [Previous Amount] * 3 as Previous_Amount FROM [pensions]

instead of

SELECT [Previous Amount] * 3as Previous_Amount FROM [pensions]
 
I noticed that you had the * wildcard incorrectly placed and there was no space before the "as" and no comma after [Previous Amount] according to your post.

the bottom should work:

"SELECT [Previous Amount] as Previous_Amount, " & My_CPI_session & " as My_CPI FROM [pensions]"
 
I noticed that you had the * wildcard incorrectly placed and there was no space before the "as" and no comma after [Previous Amount] according to your post.

the bottom should work:

"SELECT [Previous Amount] as Previous_Amount, " & My_CPI_session & " as My_CPI FROM [pensions]"
 
Back
Top