0

I have this sql statement:

DECLARE @option_id INT;

SELECT DISTINCT product_options.option_id
INTO   @option_id
FROM   product_options,
       product_options_descriptions
WHERE  product_options.product_id = '31288'
       AND product_options_descriptions.option_name = "Color";

SELECT @option_id;

Which works fine. What I would like to do is is use @option_id to select multiple ids into an array. However as far as I can tell DECLARE @var only works with single values and I can't find any information on array datatypes in sql.

In outline I want to do the following

declare @option_id;
SELECT @option_id;
DECLARE @id_array;
SELECT into @id_array WHERE id = @option_id;
DECLARE @return_array;
FOREACH @id IN @id_array {
@return_array[] = SELECT value FROM column where id = @id
}
SELECT @return_array

Does anyone know where I can find tutorials ect to achieve this?

1 Answer 1

1

You can use temporary table , table prefixed with #

CREATE TABLE #YourTable (  
  YourColumn int 
) 

LInk : http://www.sqlteam.com/article/temporary-tables

For mysql syntax : http://dev.mysql.com/doc/refman/5.1/en/create-table.html

Sign up to request clarification or add additional context in comments.

5 Comments

and then I can run standard sql commands on it? Also would I need to drop the table afterwards or does this count as a tempory table?
Yes you can run your treatments normally, and drop your table in the end of treatment
Cheers, that is what I wanted, Big green tick for you
I'am happy to help you tracer tong Thank you
That syntax (and article) is for sql-server. For mysql, you want CREATE TEMPORARY TABLE ....

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.