t-sql 2012 pass in null values

  • The following t-sql 2012 works fine in sql management studio. However when I place it in a .net 2010 web form application, I am told the sql does not work when the parameter values are null. Thus can you tell me what I can change in the sql below that will accept null as 3 possible input values?

    SELECT i.[lastName]

    ,i.[firstName]

    ,i.[middleName]

    ,i.[suffix]

    ,a.[userid]

    ,a.schoolnum

    ,a.spa

    ,a.mrref

    from [OPS].[dbo].[Identity] i

    inner join [OPS].[dbo].[Person] p on i.identityID = p.currentIdentityID

    inner join [OPS].[dbo].[UserAccount] u on u.personID = p.personID

    inner join [CampusOps].[dbo].[AtnLtrUsers] a on a.userid =u.username

    where (i.[lastName] like '%' + @lname + '%' or i.[firstName] like'%' +

    @fname + '%'

    or i.[middleName] like'%' + @mname + '%')

    or (@fname is null and @lname is null and @mname is null)

    order by i.[lastName], i.[firstName], i.[middleName]"

  • Quick thought, can you change this to a stored procedure and set default values for the parameters?

    😎

Viewing 2 posts - 1 through 1 (of 1 total)

You must be logged in to reply to this topic. Login to reply