Lobotomybeats


Hello,

I am writing a stored procedure that is supposed to get info out of a table.

E.g


TABLE FRUITS
Id Value1 Value2
1 Apple Banana
1 Apple null

1 grape null
2 Plum Melon
2 Plum null
3 berry null

As you see there are six items with three ids but different info.

If I select * From fruits WHere id =1 I get three rows.

1 Apple Banana
1 Apple null

1 grape null

But In this case I just want to return two rows, namely:

1 Apple Banana

1 grape null

Thankful for any suggestions, preferably in codeexamples.

Best Regards,

L




Re: Need help with a sp

Geert Verhoeven


Hi,

The question is pretty vague. Can you please explain more what the context is of your problem.

What do you want if you have records like this:

TABLE FRUITS
Id Value1 Value2
1 Apple Banana
1 Apple Melon
1 Apple null

1 grape null
2 Plum Melon
2 Plum null
3 berry null

Which rows do you want to be returned for ID=1

Greetz,

Geert

Geert Verhoeven
Consultant @ Ausy Belgium

My Personal Blog







Re: Need help with a sp

Lobotomybeats

Hi Geert and thanks,

In your case I want the return value

id value1 value2

1 Apple Banana

1 Apple Melon

1 Grape null

I am building an application which in the first window chooses a value (apples) and then depending on that value gets to choose other values (value2 bananas, melons).

Then I want to fetch all things that matches apples and if they have a value2 these should be fetched first and in that case the null value2 should be ignored.

Why I have a table entry 1 apple null What if the user deletes the rows with id= 1 with a value2, that fruit configuration should still exist!

Please help.

L






Re: Need help with a sp

Menthos

Surely that's just a simple Select statement

e.g SELECT Value2 WHERE Value1='Apple'

I'd have thought that your ID field wouldn't factor in retrieving the Value2 results.


"
Why I have a table entry 1 apple null What if the user deletes the rows with id= 1 with a value2, that fruit configuration should still exist!"

Not quite sure what you mean by this, based on your example, you're always going to lose the fruit 'configuration' if you delete rows using the ID field.