Addition of two numbers

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • sonia.sardana
    New Member
    • Jul 2006
    • 95

    Addition of two numbers

    1) DECLARE @num1 int , @num2 int
    Above statement declares two variables num1 and num2.

    I want the addition of two numbers--
    SET @num1=10
    Error-Must declare the scalar variable "@num1".

    2) DECLARE @num1 int =10, @num2 int= 20
    is it possible to initialise the variables in the declaration as in the above case.
  • Delerna
    Recognized Expert Top Contributor
    • Jan 2008
    • 1134

    #2
    1) are you saying that you have these 2 lines of code
    Code:
    DECLARE @num1 int , @num2 int
    SET @num1=10
    and you are getting this error
    Error-Must declare the scalar variable "@num1".

    if so then I am staring and staring at the lines and I can't for the life of me see anything wrong with them. The error is saying you havn't declared the variable @num1

    Where have you written those two lines? In a stored proc, In query analyser or where ???

    2) No, I dont think so. But try and see, you will get an error if you can't

    Comment

    • sonia.sardana
      New Member
      • Jul 2006
      • 95

      #3
      Query Analyzer......
      Error is there u can check it out by executing it ......

      Triggers are also known as Stored procedures na........

      Comment

      • Delerna
        Recognized Expert Top Contributor
        • Jan 2008
        • 1134

        #4
        Code:
        DECLARE @num1 int , @num2 int
        SET @num1=10
        Nope, it works fine for me in query analyser ???

        Comment

        • sonia.sardana
          New Member
          • Jul 2006
          • 95

          #5
          In SQL Server 2000,Query Analyzer and Enterprise Manager are different.
          But in SQL Server 2005,there is only one window where on the LEFT HAND SIDE,u r able to view all ur tables, and on the RHS,u write query.


          U R working on SQL 2000 or 2005??

          I m working on SQL Server 2005.

          Comment

          • Delerna
            Recognized Expert Top Contributor
            • Jan 2008
            • 1134

            #6
            I have not had the pleasure of using SQL 2005 as yet, I use 2000.

            Comment

            • ck9663
              Recognized Expert Specialist
              • Jun 2007
              • 2878

              #7
              Originally posted by sonia.sardana
              In SQL Server 2000,Query Analyzer and Enterprise Manager are different.
              But in SQL Server 2005,there is only one window where on the LEFT HAND SIDE,u r able to view all ur tables, and on the RHS,u write query.


              U R working on SQL 2000 or 2005??

              I m working on SQL Server 2005.

              Click New Query. Paste your code on the query window. Click execute (or press F5)

              -- CK

              Comment

              • sonia.sardana
                New Member
                • Jul 2006
                • 95

                #8
                Hey Ck,Can u please tell me how to add two numbers ?????

                Comment

                • JovieUrbano
                  New Member
                  • Feb 2008
                  • 8

                  #9
                  Originally posted by sonia.sardana
                  Hey Ck,Can u please tell me how to add two numbers ?????
                  try this..

                  Declare @cnt01 int, @cnt02 int
                  set @cnt01=10
                  set @cnt02=10
                  select @cnt01+@cnt02

                  Comment

                  Working...