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. Pass Table Name to a function dynamically

Pass Table Name to a function dynamically

Scheduled Pinned Locked Moved Database
helpcareer
3 Posts 3 Posters 0 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.
  • M Offline
    M Offline
    Mohammad Al Hoss
    wrote on last edited by
    #1

    Hi i need to pass table name and to a function dynamically anyone can help

    Mohammad Al Hoss Development To Me Is A Pleasure more than a Job

    A M 2 Replies Last reply
    0
    • M Mohammad Al Hoss

      Hi i need to pass table name and to a function dynamically anyone can help

      Mohammad Al Hoss Development To Me Is A Pleasure more than a Job

      A Offline
      A Offline
      Ashfield
      wrote on last edited by
      #2

      Well, you can pass the table name as a variable, but as far as I know you cannot execute dynamic sql in a function so it will be of no use to you.

      Bob Ashfield Consultants Ltd

      1 Reply Last reply
      0
      • M Mohammad Al Hoss

        Hi i need to pass table name and to a function dynamically anyone can help

        Mohammad Al Hoss Development To Me Is A Pleasure more than a Job

        M Offline
        M Offline
        Mycroft Holmes
        wrote on last edited by
        #3

        I knew this would come up sooner or later. SQL Server Central had an article (sorry no link) that used XML to pass the table and data to a function. Stored proc expamle Declare @X xml Set @X = (SELECT RegionID, sum(Amount) Amount FROM FactTran where PeriodID = @PeriodID and WFGroupID = @WFGroupID and TranTypeID = @TranTypeID and ISNULL(BUID,7) = 7 Group By RegionID For XML Raw ('RegionID'), ROOT('Regions')) Function example LEFT OUTER JOIN (SELECT x.item.value('@RegionID[1]', 'VARCHAR(100)') AS RegionID, x.item.value('@Amount[1]', 'Decimal(30,2)') AS Amount FROM @x.nodes('//Regions/RegionID') AS x(item)) R on R.RegionID = A.RegionID These are my usage and may give you some idea if you cannot find the article.

        Never underestimate the power of human stupidity RAH

        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