How to Declare a scalar variable in ASP.

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Raman Pahwa
    New Member
    • Jul 2008
    • 43

    How to Declare a scalar variable in ASP.

    Hi

    Suppose, i have a scalar variable named "@numberlis t".

    How should i declare it in ASP coding
  • DrBunchman
    Recognized Expert Contributor
    • Jan 2008
    • 979

    #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

    Comment

    • Raman Pahwa
      New Member
      • Jul 2008
      • 43

      #3
      Originally posted by DrBunchman
      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

      Comment

      • DrBunchman
        Recognized Expert Contributor
        • Jan 2008
        • 979

        #4
        To declare a variable in ASP you just
        Code:
        Dim VariableName
        But I can't imagine that this is what you are trying to achieve.

        Dr B

        Comment

        • Raman Pahwa
          New Member
          • Jul 2008
          • 43

          #5
          Originally posted by DrBunchman
          To declare a variable in ASP you just
          Code:
          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.

          Comment

          • DrBunchman
            Recognized Expert Contributor
            • Jan 2008
            • 979

            #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

            Comment

            • Raman Pahwa
              New Member
              • Jul 2008
              • 43

              #7
              Originally posted by DrBunchman
              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

              Code:
              dim m,@numberlist
              ctr=1
              
              Set xml = CreateObject("Microsoft.XMLHTTP")
              
              DECLARE @numberList varchar(700)
              set rs=sconn.execute("Select @numberList = IsNull(mobile + ',' + @numberList, NULLIF( mobile, @numberList)) from <tablename> where <condition>")
              set rs=sconn.execute("Select @numberList as numberList")
              while not rs.eof
              
              m=rs.Fields("numberlist").Value
              
              
              Response.Write (ctr &" - - " & m &"<BR>")
              ctr=ctr+1
              rs.movenext
              wend

              error: Invalid character at
              dim m,@numberlist
              ----------^

              Comment

              • DrBunchman
                Recognized Expert Contributor
                • Jan 2008
                • 979

                #8
                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
                Code:
                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:
                Code:
                Dim sSQL
                sSQL = ""
                sSQL = sSQL & " DECLARE @numberList varchar(700); "
                sSQL = sSQL & " SELECT @numberList = <column> FROM <tablename> WHERE <condition>"
                Let me know how you get on,

                Dr B

                Comment

                • Raman Pahwa
                  New Member
                  • Jul 2008
                  • 43

                  #9
                  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.Su ppose 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.

                  Comment

                  • Raman Pahwa
                    New Member
                    • Jul 2008
                    • 43

                    #10
                    Acc to your code,i m getting the following error:
                    Object required: ' DECLARE @numberList'

                    Comment

                    • DrBunchman
                      Recognized Expert Contributor
                      • Jan 2008
                      • 979

                      #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

                      Comment

                      • Raman Pahwa
                        New Member
                        • Jul 2008
                        • 43

                        #12
                        Originally posted by DrBunchman
                        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.Su ppose 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

                        Comment

                        • DrBunchman
                          Recognized Expert Contributor
                          • Jan 2008
                          • 979

                          #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:

                          Code:
                          sSQL = " INSERT INTO <table name> (<Column Name>)"
                          sSQL = sSQL & " VALUES('" & Var1 & ", " & Var2 & ", " & Var3 & "') "
                          Hope this helps,

                          Dr B

                          Comment

                          • Raman Pahwa
                            New Member
                            • Jul 2008
                            • 43

                            #14
                            Originally posted by DrBunchman
                            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:

                            Code:
                            sSQL = " INSERT INTO <table name> (<Column Name>)"
                            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,57 6)

                            Comment

                            Working...