• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

SQL Where Select

 
Tempora Telora
Ranch Hand
Posts: 83
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello all,

My questions is how do you limit a result set based upon an entry that your passing. If it was java I would do a simple if statment but I think a case statement will have to do. I can ONLY do this in SQL. What I am working in cannot handel any operation to limit the result set.

Here is the pseudo

select ID from Table
where Flag = y and Num = ( if num = 'all' return *
else return num)

Thanks,
Lammy
[ March 20, 2007: Message edited by: Randy Tatham ]
 
Keith Lynn
Ranch Hand
Posts: 2409
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Randy Tatham:
Hello all,

My questions is how do you limit a result set based upon an entry that your passing. If it was java I would do a simple if statment but I think a case statement will have to do. I can ONLY do this in SQL. What I am working in cannot handel any operation to limit the result set.

Here is the pseudo

select ID from Table
where Flag = y and Num = ( if num = 'all' return *
else return num)

Thanks,
Lammy

[ March 20, 2007: Message edited by: Randy Tatham ]


What about using a couple of PreparedStatements?

One statement could be

"SELECT ID FROM TABLE WHERE FLAG=?",

and the other could be

"SELECT ID FROM TABLE WHERE FLAG=? AND NUM=?".

Then you could decide which to use based on num.
[ March 20, 2007: Message edited by: Keith Lynn ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic