Results 1 to 4 of 4
  1. #1
    Join Date
    Jan 2003
    Location
    Washington, DC
    Posts
    24

    Question Unanswered: How can I store results to a variable?

    I use VB and simply need a way to store the result of a SQL query into
    a variable. Is this possible? For example if the table has a person's age
    as 40 for Robert Smith etc. I need to store the age to a variable. In VB
    I typically return the table into a datagrid then search the grid for what
    I'm looking for. This works but is slow on large tables. I was hoping
    for something like this:


    SET myVar = AGE FROM tblMAIN WHERE ID = socsecno

    but SQL doesn't like it.


    Thanks.

  2. #2
    Join Date
    Mar 2003
    Posts
    1

    Re: How can I store results to a variable?

    Originally posted by BobbyJ
    I use VB and simply need a way to store the result of a SQL query into
    a variable. Is this possible? For example if the table has a person's age
    as 40 for Robert Smith etc. I need to store the age to a variable. In VB
    I typically return the table into a datagrid then search the grid for what
    I'm looking for. This works but is slow on large tables. I was hoping
    for something like this:


    SET myVar = AGE FROM tblMAIN WHERE ID = socsecno

    but SQL doesn't like it.


    Thanks.
    in SQL Server:
    DECLARE @myAge int
    SET myAge = (SELECT age FROM tblMain WHERE id = socsecno)

  3. #3
    Join Date
    Jan 2003
    Location
    Washington, DC
    Posts
    24

    Thumbs up Ok.

    Thanks!

    BobbyJ

  4. #4
    Join Date
    Feb 2002
    Location
    Houston, TX
    Posts
    809
    or

    DECLARE @myAge int
    SELECT @myAge = age FROM tblMain WHERE id = socsecno
    Paul Young
    (Knowledge is power! Get some!)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •