I have the following sql query

VB Code:
  1. SELECT A, B, C, (SELECT E FROM TABLE_Y WHERE D=@A AND E=@B and F=@C) AS TABLE_Y_DATA FROM TABLE_X WHERE A=@A AND B=@B and C=@C

result:

A B C TABLE_Y_DATA
----------------------------------
1 4 55 HYDSA
77 3 22 OGYITY

etc

Note that you only get ONE hit with the sub query

Now, the tricky part is that parameters a, b and c can be * from the application (they are numbers so they are by default set to -1 which equals *

How can I write this as a stored procedure where I take into account the parameters a, b and c? I mean, if A=77, B=-1 and C=42 then the B-statements should not be used. Please note that the database is NOT designed with -1 in mind. That is only on application level.

Im really stuck here!! Perhaps there is an easier way to write the sql query than then one I made?

/Henrik