File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

SQL Where Select

 
Tempora Telora
Ranch Hand
Posts: 83
  • 0
  • 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: 2399
  • 0
  • 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