SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Zealot
    Join Date
    Dec 2006
    Posts
    182
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Assign results as variables

    I want to create function and I need to get the results 2 columns and assign them to variables so I can use them again, but for some reason I can only get it to work if I run the select statement twice :

    Code:
    SELECT lng INTO @zlng FROM zipcodes WHERE zip=@z LIMIT 1;
    SELECT lat INTO @zlat FROM zipcodes WHERE zip=@z LIMIT 1;
    I get an "Undeclared variable: lat" error if I try this:

    Code:
    SELECT lng INTO @zlng, lat INTO @zlat FROM zipcodes WHERE zip=@z LIMIT 1;
    Is there a way to do both into one statement? Thanks!

  2. #2
    SitePoint Wizard bronze trophy
    Join Date
    Jul 2008
    Posts
    5,757
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Code:
    SELECT lng, lat INTO @zlng, @zlat

  3. #3
    SitePoint Zealot
    Join Date
    Dec 2006
    Posts
    182
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thank you, sir!

  4. #4
    SitePoint Zealot
    Join Date
    Dec 2006
    Posts
    182
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Related Question, when I try and call a stored procedure, it errors with "can't return a result set in the given context". I tried a super simple one:
    Code:
    delimiter |
    CREATE PROCEDURE getall()
    	BEGIN
    		SELECT storeno FROM locations;
    	END |
    delimiter ;
    and call it with
    Code:
    CALL getall();
    . How do I return the results? Thanks.


Bookmarks

Posting Permissions

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