Groups | Blog | Home
all groups > sql server reporting services > april 2005 >

sql server reporting services : I need help with SELECT statement


Vanessa Lee
4/14/2005 6:20:04 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

andrei
4/15/2005 10:59:25 AM
Vanessa,

It looks like you can't select unique values from col1 because then what
would be the value of col2 for the displayed col1?
Ex:
col1 col2
A 1
A 2
B 3

after the select you would have:

A (what value goes here, 1 or 2 ?)
B 3

You could provide one more condition for the value in field col2 (like
max(), for ex.)

select col1, max(col2) from table1 where col3 <= @v group by col1
******
I'm afraid I don't quite get what you need when you say ' "WHERE" col3
always has
maximum value from all possible values but is <= @V'
Just an assumption : try this

select col1, max(col2), max(col3) from table1 where col3 <= @v group by col1

Andrei.



[quoted text, click to view]

AddThis Social Bookmark Button