Products

Solutions

Resources

Partners

Community

Blog

About

QA

Ideas Test

New Community Website

Ordinarily, you'd be at the right spot, but we've recently launched a brand new community website... For the community, by the community.

Yay... Take Me to the Community!

Welcome to the DNN Community Forums, your preferred source of online community support for all things related to DNN.
In order to participate you must be a registered DNNizen

HomeHomeArchived Discus...Archived Discus...Developing Under Previous Versions of .NETDeveloping Under Previous Versions of .NETASP.Net 2.0ASP.Net 2.0Creating the moduleCreating the module
Previous
 
Next
New Post
4/21/2007 11:40 AM
 

Kvietinis wrote

Well yes, if I would like to get the exact Xs, I need the condition.. But what if want to get all of Xs.. the WHERE clause do not fit here and no need for parameter.

Or I do not understand something?

 

If you want the sproc to return all records or selected records you can do something like this.

GetXs:

@Xid int
AS
Select * FROM Xs WHERE (@Xid = 0 And Xid > 0) or Xid = @Xid

(@Xid = 0 And Xid > 0): If Xid parameter is 0 then you want all records. SQL sees this as (0=0 And Xid >0) so if @Xid is not 0 the whole first statement returns false for each record so no records are returned

Xid = @Xid:  This statement get the records based on the specific ID.  If the first statement is true, this really has not effect since all records were selected in the first statement.  If the first statement is false (AKA: @Xid != 0), the records are only selected for the specifc Xid.


I am writing this from memory, so if it does not work let me know and I will double check the syntax / where statement.  I do not have access to my development machine at this time .

 

 
New Post
4/21/2007 11:59 AM
 

ssmehaffie wrote

@Xid int
AS
Select * FROM Xs WHERE (@Xid = 0 And Xid > 0) or Xid = @Xid

Brilliant :) Normally I just use 2 stored procedures. One to select all the records and one to return specific ones. Now I just need one stored procedure to do the same thing.



Michael Washington
http://ADefWebserver.com
www.ADefHelpDesk.com
A Free Open Source DotNetNuke Help Desk Module
 
New Post
4/21/2007 11:40 PM
 

The nice thing is if you have multiple parameters you can use the same logic, just have multiple where clauses like the one above.

@Xid int
AS
Select * FROM Xs

WHERE (@Xid = 0 And Xid > 0) or Xid = @Xid

AND (@MyID = 0 And MyID >0) or MyId = @MyID

The bad thing is I am working on a project for a company and just wrote a selectAll SPROC and was going to write another SPROC for the searches that would be available.  I forgot all about this until I saw this post.  Get go refactor my sproc.

 
New Post
4/22/2007 3:52 PM
 

Thanks, guys for advices.. I haven't tried yet, but I understood the idea.

 
Previous
 
Next
HomeHomeArchived Discus...Archived Discus...Developing Under Previous Versions of .NETDeveloping Under Previous Versions of .NETASP.Net 2.0ASP.Net 2.0Creating the moduleCreating the module


These Forums are dedicated to discussion of DNN Platform and Evoq Solutions.

For the benefit of the community and to protect the integrity of the ecosystem, please observe the following posting guidelines:

  1. No Advertising. This includes promotion of commercial and non-commercial products or services which are not directly related to DNN.
  2. No vendor trolling / poaching. If someone posts about a vendor issue, allow the vendor or other customers to respond. Any post that looks like trolling / poaching will be removed.
  3. Discussion or promotion of DNN Platform product releases under a different brand name are strictly prohibited.
  4. No Flaming or Trolling.
  5. No Profanity, Racism, or Prejudice.
  6. Site Moderators have the final word on approving / removing a thread or post or comment.
  7. English language posting only, please.
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out