I am trying to use a condition in stored procedure which is created by using multiple tables. Can anybody please help me to solve this problem?
I want to skip a parameter if the parameter value is null
or nil
.
Example: I want to see all the cities of a country starting with 'A'
if user select a country name from drop down list and want to see all the cities starting with 'A'
of all countries if user does not select any country.
Please suggest me what will be placed in the following line:-
WHERE substring(cityname,1,1)='A' and countryname=@countryname
Eagerly awaiting suggestion from anybody.
Thanks, Nowshad
I want to skip a parameter if the parameter value is null
Simply check to see whether your parameters are NULL
or whether they specify a predicate. If they specify a predicate, then check that it matches.
SUBSTRING(CityName, 1, 1) = 'A'
AND ( @CountryName IS NULL OR CountryName = @CountryName )
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.