Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 sql - pulling data from specific rows

Author  Topic 

Rachel1976
Starting Member

1 Post

Posted - 2006-11-12 : 21:09:38
I have a table, multiple columns, thousands of rows.

Six of the columns is the data that i need to work with...

col1, col2, col3, col4, col5, col6

col1 and col2 - go together - example. col1 = amount col2 = description
col3 and col4 - go together col3 = amount col4 description
col5 and col6 - go together col5 amount and 6 description

i need to pull search the table based on an auto number "id" and pull in the necessary two columns that correspond with a set value in the description.

example:

if col4 has "fee applied" in the description i need to pull the amount.

Please help...

Thank you in advance

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2006-11-12 : 21:49:32
Don't quite understand what you really want.

Is it this ?

select col1, col2, col3, col4, col5, col6
from table
where id = @id



Try posting some sample data and the result that you want


KH

Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2006-11-13 : 06:41:38
Your table structure seems denormalised. Can you also post table structure in addition to sample and expected data?

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2006-11-13 : 06:55:28
Something like this
SELECT		CASE
WHEN col2 = @WantedDescription THEN col1
WHEN col4 = @WantedDescription THEN col3
WHEN col6 = @WantedDescription THEN col5
END [Amount],
CASE
WHEN col2 = @WantedDescription THEN col2
WHEN col4 = @WantedDescription THEN col4
WHEN col6 = @WantedDescription THEN col6
END [Description]
FROM YourTable
WHERE ID = @SomeID


Peter Larsson
Helsingborg, Sweden
Go to Top of Page
   

- Advertisement -