sql >> Databáze >  >> RDS >> Sqlserver

SQL Server Ignorovat vyhledávání v poli, pokud je parametr null

Toto je častá a duplicitní otázka. Můžete použít níže:přidat "NEBO @parametr je null" ke všem vašim kritériím

Select tblQuickRegister.memberId , tblUserLogin.lastLogin , tblQuickRegister.dob,tblPhysicalAttributes.height, tblHomeTruth.religion, tblEducation.highestQualification , tblOccupation.occupation, tblPicture.profilePic1 from tblQuickRegister full outer join tblUserLogin on tblQuickRegister.memberId = tblUserLogin.memberId full outer join tblPhysicalAttributes on tblQuickRegister.memberId = tblPhysicalAttributes.memberId full outer join tblHomeTruth on tblQuickRegister.memberId = tblHomeTruth.memberId full outer join tblEducation on tblQuickRegister.memberId = tblEducation.memberId full outer join tblOccupation on tblQuickRegister.memberId = tblOccupation.memberId full outer join tblPicture on tblQuickRegister.memberId = tblPicture.memberId full outer join tblMaritalStatus on tblQuickRegister.memberId = tblMaritalStatus.memberId full outer join tblContact on tblQuickRegister.memberId = tblContact.memberId where (tblQuickRegister.sex = @sex or @sex is null) And (tblMaritalStatus.maritalStatus = @maritalStatus or @maritalStatus is null) And ((DATEDIFF(DAY,Convert(date,tblQuickRegister.dob),getdate())/365 >= @minage) or @minage is null) And ((DATEDIFF(DAY,Convert(date,tblQuickRegister.dob),getdate())/365 <= @maxage) or @maxage is null) And (tblContact.[state] = @state or @state is null) And (tblContact.city = @city or @city is null)

  1. BCP nevrací žádné chyby, ale také nekopíruje žádné řádky

  2. Přidejte sloupec do tabulky, pokud ještě neexistuje

  3. Jak používat součet, průměr a počet v příkazu Select - SQL Server / TSQL výukový program, část 128

  4. Získat nejbližší zeměpisnou délku a šířku z databázové tabulky MSSQL?