473,418 Members | 2,075 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,418 software developers and data experts.

How to select two rows within same column and display result as separate column

hi Folks,

i came across a situation for which still i couldn't get a solution.

i have table like below(some other columns are also there)

option value
------- ------
100 1
101 200
102 .
103 .
. .

i have to display result with two columns like below

ValueForOption100 ValueForOption101
---------------------------- ---------------------------
1 200

(the value for option 100 will be either 0 or 1. based on the value for option 100 the value for option 101 will change in my application. this is the reason i need to get a report like this )
anyone pls help me. it would be of great help.
Jul 12 '07 #1
6 4068
Motoma
3,237 Expert 2GB
Could you tell us what language you are doing this in?
Jul 12 '07 #2
Infide
28
hi Folks,

i came across a situation for which still i couldn't get a solution.

i have table like below(some other columns are also there)

option value
------- ------
100 1
101 200
102 .
103 .
. .

i have to display result with two columns like below

ValueForOption100 ValueForOption101
---------------------------- ---------------------------
1 200

(the value for option 100 will be either 0 or 1. based on the value for option 100 the value for option 101 will change in my application. this is the reason i need to get a report like this )
anyone pls help me. it would be of great help.
To pivot out data on different rows into seperate columns try using a case statement.

SELECT CASE WHEN Option = 100 then value else null end as Option100,
case when Option = 101 then value else null end as Option101
from Table

If you dont' want to use a case statement, let's say because you have 10 or more options you could use a cursor.
Iterate through the rows, add a column to a temporary table for each row and then return the table.
Jul 12 '07 #3
Could you tell us what language you are doing this in?
hi

am using delphi application and the values for option 100 and 101 will be stored already in database(it is a configuration options option100 is a check box so it will have only two values 0 or 1 And option101 is a textbox type and it will be allowed to change the value only when option100 is checked. this is how the configuration is made in front end)

what i want is an sql query to select those options in two colums as i mentioned in my first post.

thank you
Jul 13 '07 #4
To pivot out data on different rows into seperate columns try using a case statement.

SELECT CASE WHEN Option = 100 then value else null end as Option100,
case when Option = 101 then value else null end as Option101
from Table

If you dont' want to use a case statement, let's say because you have 10 or more options you could use a cursor.
Iterate through the rows, add a column to a temporary table for each row and then return the table.
it is not working.. it is not needed to do any manipulation with datas. the datas are manipulated and stored in table already.

i just want to select the values in option100 and option101 as two separate columns

thanks for your help yaar
Jul 13 '07 #5
Infide
28
it is not working.. it is not needed to do any manipulation with datas. the datas are manipulated and stored in table already.

i just want to select the values in option100 and option101 as two separate columns

thanks for your help yaar
We're not manipulating the data, we are merely pivoting it out. If SQL case is not working see what the syntax is for a case or switch statement on whatever platform you are using.
Jul 13 '07 #6
We're not manipulating the data, we are merely pivoting it out. If SQL case is not working see what the syntax is for a case or switch statement on whatever platform you are using.

i got it. but am gettng result as

option100 option101
1 Null
Null 200
Jul 13 '07 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Sven Reifegerste | last post by:
Hi, i have a table with INT columns id,key,b1,b2,c1,c2, having 1.500.000 rows. 'key' and 'id' are indexed (Kardinality 385381) and id (Kardinality 1541525). Performing a SELECT * FROM...
4
by: Bruce Pullum | last post by:
I have a datagrid that I am using a DataView with. All works great for the sorting of the columns. However, after I sort the column, and then try and select a data row to edit, the row selected...
4
by: psql-mail | last post by:
I am running a SELECT to get all tuples within a given date range. This query is much slwoer than i expected - am i missing something? I have a table 'meta' with a column 'in_date' of type...
3
by: Tcs | last post by:
My backend is DB2 on our AS/400. While I do HAVE DB2 PE for my PC, I haven't loaded it yet. I'm still using MS Access. And no, I don't believe this is an Access question. (But who knows? I...
4
by: Nick Barr | last post by:
Hi, I am trying to gather stats about how many times a resource in our web app is viewed, i.e. just a COUNT. There are potentially millions of resources within the system. I thought of two...
6
by: jjturon | last post by:
Can anyone help me?? I am trying to pass a Select Query variable to a table using Dlookup and return the value to same select query but to another field. Ex. SalesManID ...
2
by: dschectman | last post by:
This appears to be a feature of IE JavaScript. I am running IE 6.0 with the latest patches from Microsoft. Are there any workarounds other than re-coding the source HTML to place all the...
5
by: rAinDeEr | last post by:
Hi, I have a web application with a table to store terms and conditions of a Company. This may some times run into many pages and some times it may be just a few sentences. It is a character...
4
tjc0ol
by: tjc0ol | last post by:
Hi guys, I'm a newbie in php and I got error in my index.php which is: 1054 - Unknown column 'p.products_id' in 'on clause' select p.products_image, pd.products_name, p.products_id,...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.