Products

Solutions

Resources

Partners

Community

Blog

About

QA

Ideas Test

New Community Website

Ordinarily, you'd be at the right spot, but we've recently launched a brand new community website... For the community, by the community.

Yay... Take Me to the Community!

Welcome to the DNN Community Forums, your preferred source of online community support for all things related to DNN.
In order to participate you must be a registered DNNizen

HomeHomeOur CommunityOur CommunityGeneral Discuss...General Discuss...A simple SQL questionA simple SQL question
Previous
 
Next
New Post
8/18/2006 3:13 PM
 

Sorry, I know that this question is not related to DNN directly, but I'm trying to add it to my DNN SQL DB.  I'm trying to make my table name as a variable.  The Function below is wrong because I'm using the @Table_Name in my Select Statement.  If I use the Exec (@SqlStmt) command, I can not return the result found.  Any idea on how I can re-write this function?  

Create Function Test(@Table_Name)

RETURNS int

AS

Begin

          Declare @Returned_val as int

         Select @Returned_Val = A.Code

         from @Table_Name A

          where A.ID = 5

 

        Return @Returned_val

End

 

 

 
New Post
8/21/2006 9:28 PM
 
Check out using the sp_ExecuteSQL proc to execute dynamic sql. 
 
New Post
8/22/2006 3:29 PM
 

Thank you, I will do.  But, is it different than the "Exec" command?

 
New Post
8/22/2006 6:08 PM
 
They are different.  exec can be used to execute a proc from within a proc.   In your proc you will create a string variable containing the SQL you wish to run.  In this manner you can pass in a table name to use in your string variable.  You will then use exec to run sp_executesql which accepts a number of input parms, the sql string being one.

Check out documentation on sp_executesql.  Here is one link.
 
New Post
8/23/2006 3:42 PM
 

Thanks much.  This really helped.

 
Previous
 
Next
HomeHomeOur CommunityOur CommunityGeneral Discuss...General Discuss...A simple SQL questionA simple SQL question


These Forums are dedicated to discussion of DNN Platform and Evoq Solutions.

For the benefit of the community and to protect the integrity of the ecosystem, please observe the following posting guidelines:

  1. No Advertising. This includes promotion of commercial and non-commercial products or services which are not directly related to DNN.
  2. No vendor trolling / poaching. If someone posts about a vendor issue, allow the vendor or other customers to respond. Any post that looks like trolling / poaching will be removed.
  3. Discussion or promotion of DNN Platform product releases under a different brand name are strictly prohibited.
  4. No Flaming or Trolling.
  5. No Profanity, Racism, or Prejudice.
  6. Site Moderators have the final word on approving / removing a thread or post or comment.
  7. English language posting only, please.
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out