Click here to Skip to main content
15,890,438 members
Home / Discussions / Database
   

Database

 
GeneralDataRelation question Pin
IlanTal26-Mar-05 21:36
IlanTal26-Mar-05 21:36 
GeneralRe: DataRelation question Pin
Scott Serl28-Mar-05 10:06
Scott Serl28-Mar-05 10:06 
GeneralRe: DataRelation question Pin
IlanTal28-Mar-05 18:38
IlanTal28-Mar-05 18:38 
GeneralRe: DataRelation question Pin
Scott Serl29-Mar-05 6:44
Scott Serl29-Mar-05 6:44 
GeneralRe: DataRelation question Pin
IlanTal29-Mar-05 7:10
IlanTal29-Mar-05 7:10 
GeneralQuestion about SELECT Pin
_J_26-Mar-05 5:57
_J_26-Mar-05 5:57 
GeneralRe: Question about SELECT Pin
turbochimp26-Mar-05 11:35
turbochimp26-Mar-05 11:35 
GeneralRe: Question about SELECT Pin
Colin Angus Mackay29-Mar-05 1:03
Colin Angus Mackay29-Mar-05 1:03 
Instead of defaulting the value to an empty string you can leave it as null

Then you can do a select like this

CREATE PROCEDURE MyProcedure
@criteria1 int,
@criteria2 varchar(50)
AS

SELECT *
FROM MyTable
WHERE column1 = @criteria1
AND (@criteria2 IS NULL OR column2 = @criteria2)
GO


The key here is the AND... line. What it says is that if @criteria2 is null then the clause is true. If @criteria2 is not null then column2 must equal @criteria2 for the clause to be true. In an OR condition one or both sides must be true for the whole to be true.

Does this help?


My: Blog | Photos | Next SQL Presentation
WDevs.com - Open Source Code Hosting, Blogs, FTP, Mail and More


GeneralRe: Question about SELECT Pin
_J_29-Mar-05 1:41
_J_29-Mar-05 1:41 
GeneralRe: Question about SELECT Pin
Colin Angus Mackay29-Mar-05 1:48
Colin Angus Mackay29-Mar-05 1:48 
GeneralRe: Question about SELECT Pin
_J_29-Mar-05 1:51
_J_29-Mar-05 1:51 
GeneralRe: Question about SELECT Pin
Colin Angus Mackay29-Mar-05 1:56
Colin Angus Mackay29-Mar-05 1:56 
GeneralRe: Question about SELECT Pin
_J_29-Mar-05 2:02
_J_29-Mar-05 2:02 
GeneralSaving file in SQL Server Pin
dabuskol25-Mar-05 19:48
dabuskol25-Mar-05 19:48 
GeneralRe: Saving file in SQL Server Pin
turbochimp25-Mar-05 20:12
turbochimp25-Mar-05 20:12 
GeneralSELECT TOP Pin
vuthaianh25-Mar-05 12:10
vuthaianh25-Mar-05 12:10 
GeneralRe: SELECT TOP Pin
turbochimp25-Mar-05 17:49
turbochimp25-Mar-05 17:49 
GeneralSimplify a T-SQL Pin
WDI25-Mar-05 7:41
WDI25-Mar-05 7:41 
GeneralRe: Simplify a T-SQL Pin
Michael Potter25-Mar-05 8:24
Michael Potter25-Mar-05 8:24 
GeneralRe: Simplify a T-SQL Pin
WDI25-Mar-05 9:10
WDI25-Mar-05 9:10 
GeneralRe: Simplify a T-SQL Pin
Michael Potter25-Mar-05 11:34
Michael Potter25-Mar-05 11:34 
GeneralRe: Simplify a T-SQL Pin
Tony Lewis25-Mar-05 9:41
Tony Lewis25-Mar-05 9:41 
GeneralRe: Simplify a T-SQL Pin
andyharman28-Mar-05 4:32
professionalandyharman28-Mar-05 4:32 
GeneralDateTime Pin
vuthaianh25-Mar-05 5:24
vuthaianh25-Mar-05 5:24 
GeneralRe: DateTime Pin
Colin Angus Mackay25-Mar-05 6:29
Colin Angus Mackay25-Mar-05 6:29 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.