I have a parameter field with a data type of int. I want the users to be able to select one or 'all' from the dropdown list. Is there a wildcard for a integer datatype?
Dropdown list example:
All Project Ids
1001
1002
1003
1004
In cases like this I will frequently use a NULL parameter to designate 'all'; can that work for you in this case? An example of this would be something like this:
declare @.example table (integerCol integer)
insert into @.example values (1001)
insert into @.example values (1002)
insert into @.example values (1003)
insert into @.example values (1004)declare @.anIntegerParm integer
set @.anIntegerParm = null
set @.anIntegerParm = 1002if @.anIntegerParm is null
select * from @.example
else
select * from @.example
where integerCol = @.anIntegerParm-- When @.anIntegerParm is null:
-- integerCol
-- --
-- 1001
-- 1002
-- 1003
-- 1004-- When @.anIntegerParm = 1002:
-- integerCol
-- --
-- 1002select * from @.example
where @.anIntegerParm is null
or @.anIntegerParm is not null
and integerCol = @.anIntegerParm-- integerCol
-- --
-- 1002
No comments:
Post a Comment