Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
How To Pull Gender
Message
General information
Forum:
Microsoft SQL Server
Category:
SQL syntax
Title:
How To Pull Gender
Miscellaneous
Thread ID:
01510820
Message ID:
01510820
Views:
130
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
Next
Reply
Map
View

Click here to load this message in the networking platform