tsql - SQL where clause with one parameter to check either int or string field -
i have stored procedure:
alter procedure [dbo].[getclassinfo](@classid int) begin select [usergroupid] ,[gname] ,[accesscode] [dbo].[usergroup] usergroupid = @classid or accesscode = @classid end
now, want parameter i'm sending check either usergroupid
number or accesscode
string.
which solution painless check both cases using 1 parameter?
you can't have none integer values in parameter have changed varchar.
alter procedure [dbo].[getclassinfo] ( @classid varchar(50) ) begin if isnumeric(@classid + '.0e0') = 1 begin declare @classidint int = convert(int , @classid); select [usergroupid] , [gname] , [accesscode] [dbo].[usergroup] @classidint = [usergroupid]; end; if isnumeric(@classid + '.0e0') = 0 begin select [usergroupid] , [gname] , [accesscode] [dbo].[usergroup] [accesscode] = @classid; end; end;
the if statement determines if value passed integer , runs appropriate query
Comments
Post a Comment