Groups | Blog | Home
all groups > sql server dts > april 2005 >

sql server dts : I need help with SELECT statement


Vanessa Lee
4/14/2005 6:17:41 PM
Hi, Could you help me modify the SELECT statement below that would
accomplish my final goal.

SELECT col1, col2 FROM table1 WHERE col3 < @V

In col1 rows have many duplicates
col2 has unique values
col3 can have 5 possible values: 5, 10, 15, 20, 25
Variable @V can be equal to 5 or 10 or 15 or 20 or 25

The goal is to:

Return row values from col1 without duplicates, and return corresponding
values from col2 (both col1 and col2 in one row) "WHERE" col3 always has
maximum value from all possible values but is <= @V

Thank you.
Vanessa

ANTONIO LOPEZ
4/14/2005 9:06:04 PM

[quoted text, click to view]

Yunus's Group
4/15/2005 8:51:53 AM
Venessa,

You have mentioned that, col2 is unique. Is it unique in every row? or
unique for every distinct value of col1? Is the combination of col1 and
col2 unique?

When you say you do not want duplicates for col1, then which value of
col2 you would like to pick?

Also, you say col3 is always maximum value from all possible values(5,
10, 15, 20, 25) which is 25 ALWAYS? If this is the case, your select
statement will never pickup any row because you have WHERE col3 < @V
because as per your posting Variable @V can be equal to 5 or 10 or 15
or 20 or 25.

Here is the example:

col1 col2 col3
--------- -------- ----------
LA house1 25
LA house2 25
LA house3 25
LA house4 25
Based on above illustration, how would you like the resulting recordset
should be?
AddThis Social Bookmark Button