So if my store procedure is called with a null item I want to make it ” (otherwise it won’t work with my result list)
How does one do this?
I would like my code to spit out the population for one country if the country input was US,null,null, or I want it more specific population if US,New York, New York City is put in. So population of New York City.
Create procedure [dbo].[GetPopulation]
@CountryCode varchar(3),
@State varchar(80)=null,
@City varchar(80)=null
as
if @State is Null
@State = ''
if @City is Null
@City = ''
select Population
FROM Countries
Where CountryCode = @CountryCode AND State = @State AND City=@City
If I am right you want to ignore where clause’s when parameter is null
In case your problem is the application parameters the procedure run’s with, then default param’s to ”
Run the procedure as
dbo.GetPopulation 'US'for US or