0

Background:

creating a database that has multiple identical inputs with unique identifiers, for example: input_option_1, data_type_1, input_option_2, data_type_2, etc... input_option_1, data_type_1 and input_option_2 and data_type_2 are separate rows and inputs. input_option_1, data_type_1 are row 1 and input_option_2 and data_type_2 is row 2.

Process:

when i create a simple query against the data the code looks like this:

use DB_test2
select input_option_1, data_type_1, input_option_2, data_type_2
from dbo.page_1

Output:

the output is just as what is being called out and looks like this

input_option_1 data_type_1  input_option_2  data_type_2    
21             numerical    34A             alphanumeric

problem:

what i am trying to do is create one column for the input_option_1 and input_option_2 and one column for data_type_1 and data_type_2.

example:

this is what i want it to look like.

input_option    data_type    
21              numerical    
34a             alphanumeric
Allan
  • 17,141
  • 4
  • 52
  • 69
  • 1
    You'd be better off normalizing your database-- you don't want to have to keep creating new columns every time you add a new input. However, to get your desired results, look at using `union`... Something like `select opt1, type1 from table union select opt2, type2 from table`... – sgeddes Jan 28 '15 at 21:00
  • 1
    And the question has to do with the title... what? – Josh Part Jan 28 '15 at 21:05

1 Answers1

1

Use a UNION:

SELECT input_option_1 AS [Input_Option],
  data_type_1 AS [Data_Type]
FROM dbo.Page_1
UNION ALL
SELECT input_option_2 AS [Input_Option],
  data_type_2 AS [Data_Type]
FROM dbo.Page_1
ORDER BY [Input_Option],
   [Data_Type]

This will work but as you add more columns you'd need to modify this query, it's obviously not optimal but it is a solution.

T McKeown
  • 12,971
  • 1
  • 25
  • 32