Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Compare Column values

Status
Not open for further replies.

TSO456

Technical User
Jul 23, 2001
57
0
0
US
Hello,

I have a table in SQL server that has two columns with different dollar values. I would like to create a query that looks at each value in column 1 and compares that value to each value in column two.

I would like to extract the values in column 1 that are less than 5% the values in column 2. Remember I have to compare each and every value in column 1 to all of the values in column 2, not just one value to one value.

Many thanks for your help

Jill
 
Does this compare each and every row in column 1 to all the rows of column 2 ?
 
if you had a table

Col1 Col2
1 2
3 4

The 1 would be compared with the 2 and the 3 with the 4 and so on down the table

did you want the value in Col1 i.e. 1 to be compared with every value in col2 i.e. 3 and 4 ?

Dbomrrsm
 
Hi Dbomrrsm

Yes, I want the value in Col1 i.e. 1 to be compared with every value in col2 i.e. 2 and 4. Then after this comparison is done I want the next value in Col1 i.e. 3 to compare with col2 i.e. 2 and 4

Thank you

Jill



 
SELECT COL1
WHERE COL1 < (SELECT COL2/100*5 from MYTABLE)
FROM MYTABLE

Think this will work - hopefully

DBomrrsm
 
You'll probably need to do a cross join. Warning - cross joins are extremely slow.

Questions about posting. See faq183-874
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top