Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
How To Pull Gender
Message
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Syntaxe SQL
Titre:
How To Pull Gender
Divers
Thread ID:
01510820
Message ID:
01510820
Vues:
132
I have the following. If I pass IsMale = 1, then the result set should include rows where Sex = 'M'. Same for IsFemale, but something isn't quite right.
CREATE PROCEDURE sproc_GetContacts
	@FName VARCHAR(50) = NULL,
	@LName VARCHAR(50) = NULL,
	@IsMale BIT = NULL,
	@IsFemale BIT = NULL,
	@Age VARCHAR(3) = NULL,
	@Address_Number NVARCHAR(50) = NULL,
	@Street NVARCHAR(50) = NULL,
	@City NVARCHAR(50) = NULL,
	@State CHAR(2) = NULL,
	@Zip VARCHAR(5) = NULL,
	@IsDemocrat BIT = NULL,
	@IsRepuplican BIT = NULL,
	@IsIndepedent BIT = NULL
	
AS

	SELECT	VoterID, FName, LName, Sex, Age, Address_Number, Street, City, State, Zip, Party
		FROM tblCamp_CT
		WHERE (@FName IS NULL OR FName = @FName) AND
			  (@LName  IS NULL OR LName = @LName) AND
			  (CASE @IsMale WHEN 1 THEN Sex = 'M' END) AND
			  (CASE @IsFemale WHEN 1 THEN Sex = 'F' END) AND
			  (@Age  IS NULL OR Age =  @Age) AND	
			  (@Address_Number IS NULL OR Address_Number =  @Address_Number) AND
			  (@Street IS NULL OR Street =  @Street) AND
			  (@City  IS NULL OR City = @City) AND
			  (@State  IS NULL OR State = @State) AND
			  (@Zip IS NULL OR Zip = @Zip) AND
			  (@Party  IS NULL OR Party = @Party)	
		ORDER BY FName, LName
Everything makes sense in someone's mind
public class SystemCrasher :ICrashable
In addition, an integer field is not for irrational people
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform