This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes JDBC and the fly likes SQL Where Select Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "SQL Where Select" Watch "SQL Where Select" New topic
Author

SQL Where Select

Tempora Telora
Ranch Hand

Joined: Jun 20, 2005
Posts: 83
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

Joined: Feb 07, 2005
Posts: 2367
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 ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: SQL Where Select
 
Similar Threads
limiting the size of a resultset - Breaking up large resultset into chunks
getting a range of returned rows?
SQL Server limiting result set
OutOfMemoryError
Hibernate,Query,setMaxResults