VB sql statement

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • cj

    #1

    VB sql statement

    I have a table with 3 fields (field1 is text, field2 and field3 are int)
    I want to write a sql command for VB that will return field1 and the sum
    of field2 and field3. For instance if the table had two rows

    Ted 4 7
    Fred 5 8

    the dataset returned would be

    Ted 11
    Fred 13

    Can someone give me a statement to do this?
  • Lloyd Sheen

    #2
    Re: VB sql statement


    "cj" <cj@nospam.nosp amwrote in message
    news:OoJi6OMlIH A.1680@TK2MSFTN GP06.phx.gbl...
    >I have a table with 3 fields (field1 is text, field2 and field3 are int)
    I want to write a sql command for VB that will return field1 and the sum
    of field2 and field3. For instance if the table had two rows
    >
    Ted 4 7
    Fred 5 8
    >
    the dataset returned would be
    >
    Ted 11
    Fred 13
    >
    Can someone give me a statement to do this?
    select field1 , field2 + field3 from table

    LS

    Comment

    • cj

      #3
      Re: VB sql statement

      I tried that earlier and it didn't work. Well that's confusing now it
      does. what the heck?

      Lloyd Sheen wrote:
      >
      "cj" <cj@nospam.nosp amwrote in message
      news:OoJi6OMlIH A.1680@TK2MSFTN GP06.phx.gbl...
      >I have a table with 3 fields (field1 is text, field2 and field3 are int)
      >I want to write a sql command for VB that will return field1 and the
      >sum of field2 and field3. For instance if the table had two rows
      >>
      >Ted 4 7
      >Fred 5 8
      >>
      >the dataset returned would be
      >>
      >Ted 11
      >Fred 13
      >>
      >Can someone give me a statement to do this?
      >
      select field1 , field2 + field3 from table
      >
      LS

      Comment

      • Patrice

        #4
        Re: VB sql statement

        When something doesn't work, IMO it's best to tell us directly what you
        tried and what is the error you get rather than asking how it should be done
        or sample code wihtout letting us know you already tried something....

        --
        Patrice

        "cj" <cj@nospam.nosp ama écrit dans le message de news:
        %23ZZiPyMlIHA.4 64@TK2MSFTNGP02 .phx.gbl...
        >I tried that earlier and it didn't work. Well that's confusing now it
        >does. what the heck?
        >
        Lloyd Sheen wrote:
        >>
        >"cj" <cj@nospam.nosp amwrote in message
        >news:OoJi6OMlI HA.1680@TK2MSFT NGP06.phx.gbl.. .
        >>I have a table with 3 fields (field1 is text, field2 and field3 are int)
        >>I want to write a sql command for VB that will return field1 and the sum
        >>of field2 and field3. For instance if the table had two rows
        >>>
        >>Ted 4 7
        >>Fred 5 8
        >>>
        >>the dataset returned would be
        >>>
        >>Ted 11
        >>Fred 13
        >>>
        >>Can someone give me a statement to do this?
        >>
        >select field1 , field2 + field3 from table
        >>
        >LS

        Comment

        • jeff

          #5
          Re: VB sql statement

          are field 2 and 3 numeric?

          "cj" <cj@nospam.nosp amwrote in message
          news:%23ZZiPyMl IHA.464@TK2MSFT NGP02.phx.gbl.. .
          >I tried that earlier and it didn't work. Well that's confusing now it
          >does. what the heck?
          >
          Lloyd Sheen wrote:
          >>
          >"cj" <cj@nospam.nosp amwrote in message
          >news:OoJi6OMlI HA.1680@TK2MSFT NGP06.phx.gbl.. .
          >>I have a table with 3 fields (field1 is text, field2 and field3 are int)
          >>I want to write a sql command for VB that will return field1 and the sum
          >>of field2 and field3. For instance if the table had two rows
          >>>
          >>Ted 4 7
          >>Fred 5 8
          >>>
          >>the dataset returned would be
          >>>
          >>Ted 11
          >>Fred 13
          >>>
          >>Can someone give me a statement to do this?
          >>
          >select field1 , field2 + field3 from table
          >>
          >LS

          Comment

          • Steven Cheng [MSFT]

            #6
            Re: VB sql statement

            Hi Cj,

            Does the table columns(you want to sum) be set to the correct number type
            previously or maybe the original SQL script contains some syntax error?
            Anyway, a quick way to verify it is execute it in QueryAnzlayer or
            Management studio to see whethe the result is expected.

            BTW, just for your information, ADO.NET dataset/datatable also support
            computed column. But I think generated the value at database/sql side is
            more effecient:

            #Creating Computed Columns in a DataSet
            http://www.objectsharp.com/cs/blogs/...05/20/466.aspx

            Sincerely,

            Steven Cheng

            Microsoft MSDN Online Support Lead


            Delighting our customers is our #1 priority. We welcome your comments and
            suggestions about how we can improve the support we provide to you. Please
            feel free to let my manager know what you think of the level of service
            provided. You can send feedback directly to my manager at:
            msdnmg@microsof t.com.

            =============== =============== =============== =====
            Get notification to my posts through email? Please refer to
            http://msdn.microsoft.com/subscripti...ult.aspx#notif
            ications.

            This posting is provided "AS IS" with no warranties, and confers no rights.
            --------------------
            >Date: Wed, 02 Apr 2008 10:19:26 -0400
            >From: cj <cj@nospam.nosp am>
            >User-Agent: Thunderbird 2.0.0.12 (Windows/20080213)
            >MIME-Version: 1.0
            >Subject: Re: VB sql statement
            >Path: TK2MSFTNGHUB02. phx.gbl!TK2MSFT NGP01.phx.gbl!T K2MSFTNGP02.phx .gbl
            >Xref: TK2MSFTNGHUB02. phx.gbl microsoft.publi c.dotnet.langua ges.vb:42082
            >X-Tomcat-NG: microsoft.publi c.dotnet.langua ges.vb
            >
            >I tried that earlier and it didn't work. Well that's confusing now it
            >does. what the heck?
            >
            >Lloyd Sheen wrote:
            >>
            >"cj" <cj@nospam.nosp amwrote in message
            >news:OoJi6OMlI HA.1680@TK2MSFT NGP06.phx.gbl.. .
            >>I have a table with 3 fields (field1 is text, field2 and field3 are int)
            >>I want to write a sql command for VB that will return field1 and the
            >>sum of field2 and field3. For instance if the table had two rows
            >>>
            >>Ted 4 7
            >>Fred 5 8
            >>>
            >>the dataset returned would be
            >>>
            >>Ted 11
            >>Fred 13
            >>>
            >>Can someone give me a statement to do this?
            >>
            >select field1 , field2 + field3 from table
            >>
            >LS
            >

            Comment

            • Cor Ligthert[MVP]

              #7
              Re: VB sql statement

              CJ,

              As it is about VB SQL code, do you mean something as Linq.

              There is no VB SQL code, although some people mean with this too
              Expressions.

              For the rest I don't know VB SQL code.

              Will you please tell us where this is about?

              Cor

              Comment

              Working...