Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Database & SysAdmin
  3. Database
  4. How to avoid specification of return parameters in an inline table function

How to avoid specification of return parameters in an inline table function

Scheduled Pinned Locked Moved Database
databasetutorialquestion
1 Posts 1 Posters 1 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    jophinmichael
    wrote on last edited by
    #1

    Hi guys, I am having an inlined table valued function to search the users in my site. The search is optional ie. sometimes user will search with first name, sometimes he searches with last name, and sometimes both. As of now I am using if-else statements to check whether first name is ''(empty),or last name is ''(empty) or both are ''(empty). I have two questions? 1. Is there any other way, so that I can avoid these if-else statements and make it a single query? 2. If I am using a function as shown below, I have to specify all the return parameters. Is there any way I can avoid this and return the complete table(I do not want to use stored procedures)? I'm using a freetext search,because I want to get the search results according to relevence(ranked results). ALTER FUNCTION [dbo].[Search] ( @FirstName Varchar(400),@LastName Varchar(400) ) RETURNS @SearchResults TABLE ( -- Add the column definitions for the TABLE variable here UserName Varchar(400), EmailAddress Varchar(400) ) AS BEGIN IF (@FirstName<>'' AND @LastName<>'') begin insert into @SearchResults Select Top 100 Percent UserName,EmailAddress From UsersFirst t JOIN FreetextTable(UsersFirst, FirstName, @FirstName) K On t.Id = K.[Key] JOIN UsersSecond U on t.UserId=U.Id JOIN FreetextTable(UsersSecond, LastName, @LastName) As L On U.Id = L.[Key] ORDER BY K.[Rank] DESC; end ELSE IF (@FirstName<>'') begin insert into @SearchResults Select Top 100 Percent UserName,EmailAddress From UsersFirst t JOIN FreetextTable(UsersFirst, FirstName, @FirstName) K On t.Id = K.[Key] JOIN UsersSecond U on t.UserId=U.Id ORDER BY K.[Rank] DESC; end return END Thanks In Advance

    jophin

    1 Reply Last reply
    0
    Reply
    • Reply as topic
    Log in to reply
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes


    • Login

    • Don't have an account? Register

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • World
    • Users
    • Groups