473,387 Members | 1,621 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

How to Declare a scalar variable in ASP.

Hi

Suppose, i have a scalar variable named "@numberlist".

How should i declare it in ASP coding
Aug 14 '08 #1
13 4133
DrBunchman
979 Expert 512MB
Can you explain what you mean please? I presume that your variable @numberlist is a SQL variable - what is it you are trying to do with it in ASP?

Dr B
Aug 14 '08 #2
Can you explain what you mean please? I presume that your variable @numberlist is a SQL variable - what is it you are trying to do with it in ASP?

Dr B

Ya u r right.its a sql variable but i wanna declare it in ASP
Aug 14 '08 #3
DrBunchman
979 Expert 512MB
To declare a variable in ASP you just
Expand|Select|Wrap|Line Numbers
  1. Dim VariableName
But I can't imagine that this is what you are trying to achieve.

Dr B
Aug 14 '08 #4
To declare a variable in ASP you just
Expand|Select|Wrap|Line Numbers
  1. Dim VariableName
But I can't imagine that this is what you are trying to achieve.

Dr B
I have already tried this,but it didnt work
i have to do database connectivity with SQL in ASP.
for that i want to declare the scalar variable.
Aug 14 '08 #5
DrBunchman
979 Expert 512MB
Perhaps you could show me some of your code to give me a better idea of what the problem is?

Please include any errors that you have received.

Dr B
Aug 14 '08 #6
Perhaps you could show me some of your code to give me a better idea of what the problem is?

Please include any errors that you have received.

Dr B

Expand|Select|Wrap|Line Numbers
  1. dim m,@numberlist
  2. ctr=1
  3.  
  4. Set xml = CreateObject("Microsoft.XMLHTTP")
  5.  
  6. DECLARE @numberList varchar(700)
  7. set rs=sconn.execute("Select @numberList = IsNull(mobile + ',' + @numberList, NULLIF( mobile, @numberList)) from <tablename> where <condition>")
  8. set rs=sconn.execute("Select @numberList as numberList")
  9. while not rs.eof
  10.  
  11. m=rs.Fields("numberlist").Value
  12.  
  13.  
  14. Response.Write (ctr &" - - " & m &"<BR>")
  15. ctr=ctr+1
  16. rs.movenext
  17. wend
  18.  
  19.  

error: Invalid character at
dim m,@numberlist
----------^
Aug 14 '08 #7
DrBunchman
979 Expert 512MB
You seem to be mixing up your ASP and SQL syntax so let me go through a couple of things.

SQL variables always have an @ character at the start, ASP variables cannot. The variable that you are declaring in your ASP page and the variable you are declaring in your SQL script are not the same (so they don't need to be named the same) - you are just passing the value from one to the other. You need to change the line to
Expand|Select|Wrap|Line Numbers
  1. dim m, numberlist
All of your SQL script needs to be either defined in a stored procedure or defined as a string and passed to your connection object. You have got SQL syntax (DECLARE @numberList varchar(700)) within your ASP script. Try building your SQL as a string first like this:
Expand|Select|Wrap|Line Numbers
  1. Dim sSQL
  2. sSQL = ""
  3. sSQL = sSQL & " DECLARE @numberList varchar(700); "
  4. sSQL = sSQL & " SELECT @numberList = <column> FROM <tablename> WHERE <condition>"
Let me know how you get on,

Dr B
Aug 14 '08 #8
I have a table with fields number,category,date and if i want to choose numbers of a particular category and date.
then the query will b
select number from <table name> where category=" " and date =" "
and it will display a list of numbers.

And wat if i want those numbers horizontally.Suppose i hav three numbers
123
234
678
and i want it to be like this
123,234,678
and then i hav to store it to new table.
can u help me on this. can it be possible through arrays.
Aug 14 '08 #9
Acc to your code,i m getting the following error:
Object required: ' DECLARE @numberList'
Aug 15 '08 #10
DrBunchman
979 Expert 512MB
Have you put this SQL code inside a SQL String or are you just putting it in you ASP script? Remember that SQL syntax must be passed to your connection object as a string.

Dr B
Aug 15 '08 #11
Have you put this SQL code inside a SQL String or are you just putting it in you ASP script? Remember that SQL syntax must be passed to your connection object as a string.

Dr B


I have a table with fields number,category,date and if i want to choose numbers of a particular category and date.
then the query will b
select number from <table name> where category=" " and date =" "
and it will display a list of numbers.

And wat if i want those numbers horizontally.Suppose i hav three numbers
123
234
678
and i want it to be like this
123,234,678

I have done my code till here,now wat next is:

i hav to store this data as a single record in a new table.
can u help me on this???plzzzzzz
Aug 16 '08 #12
DrBunchman
979 Expert 512MB
That should be easy enough to do.

If you have your three variables that you've already extracted from the database (let's call them Var1, Var2 & Var3) then the SQL syntax will be:

Expand|Select|Wrap|Line Numbers
  1. sSQL = " INSERT INTO <table name> (<Column Name>)"
  2. sSQL = sSQL & " VALUES('" & Var1 & ", " & Var2 & ", " & Var3 & "') "
Hope this helps,

Dr B
Aug 19 '08 #13
That should be easy enough to do.

If you have your three variables that you've already extracted from the database (let's call them Var1, Var2 & Var3) then the SQL syntax will be:

Expand|Select|Wrap|Line Numbers
  1. sSQL = " INSERT INTO <table name> (<Column Name>)"
  2. sSQL = sSQL & " VALUES('" & Var1 & ", " & Var2 & ", " & Var3 & "') "
Hope this helps,

Dr B
i have a number of variables in my table and i hav to pick data from that table to a new table automatically in horizontal order like(123,456,576)
Aug 19 '08 #14

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: Jiggaz | last post by:
Hi, Look my stored procedure : __________________ ALTER PROCEDURE dbo.CreateAccount @Nickname varchar(30), @Password varchar(15), @Email varchar(50), @Date datetime,
3
by: Ken Adeniji | last post by:
Must declare the scalar variable '@FirstName' ContactGridViewWebForm.aspx <aspqlDataSource RunAt="server" ID="SqlDataSourceContact" ...
2
by: Oded Dror | last post by:
Hi there, Please take a look at the source code and tell me whats wrong? Imports System.Data Imports System.Data.SqlClient Partial Class Test Inherits System.Web.UI.Page Const conString As...
1
by: Rama Jayapal | last post by:
the following is my code can anybody rectify my problem that i get when running my application "Must declare scalar variable @ID" <asp:GridView ID="GridView1" DataKeyNames="ID" runat="server"...
0
by: roamnet | last post by:
hi i created database file with .mdf extention ,sql server as a source and use grid view to display data there're no problem in data retrieve and display,but i want to edit it or insert new...
2
by: saravana784 | last post by:
USE GO /****** Object: StoredProcedure . Script Date: 06/09/2007 20:15:29 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO
0
by: =?Utf-8?B?V0pC?= | last post by:
I'm trying to understand the full interaction between controls on a formview that are bound to a SQLDataSource and the binding of the data using ASP.Net 2.0. When I set ConflictDetection to...
1
by: Mark | last post by:
I am really struggling with this, trying to understand why it doesn't work. I've simplified the code down to the essentials. The GridView displays in ReadOnly mode just fine, Clicking the "edit"...
1
by: Tony M | last post by:
vs 2005 - vb .net - web forms - xp pro Can't figure out why I keep getting the error Must declare the scalar variable "@CheckUser". The error happens on SqlDA.Fill(SqlDS). Just trying to make...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.