Smart questions
Smart answers
Smart people
Join Tek-Tips Forums

Member Login

Remember Me
Forgot Password?
Join Us!

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips now!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

Join Tek-Tips
*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.
Jobs from Indeed

Link To This Forum!

Partner Button
Add Stickiness To Your Site By Linking To This Professionally Managed Technical Forum.
Just copy and paste the
code below into your site.

03Explorer (TechnicalUser) (OP)
21 May 09 14:48
I am trying to make a variable driven code that the user enters criteria at the top of the SQL code and the output is custom driven.



DECLARE @StartDate DATETIME         SET @StartDate = '2009/01/01 00:00:00'
DECLARE @EndDate DATETIME           SET @EndDate   = '2009/05/20 23:59:59'
DECLARE @ELEMENT1name VARCHAR(100)     SET @ELEMENT1name = 'MemberID'
DECLARE @ELEMENT1 VARCHAR(100)         SET @ELEMENT1 = 'PatID_ValidIDPrompt'
DECLARE @ELEMENT2name VARCHAR(100)     SET @ELEMENT2name = 'Total_Calls'
DECLARE @ELEMENT2 VARCHAR(100)         SET @ELEMENT2 = 'PatID_Silencer'

  apname as @application,
  table2.elemname as @ELEMENT1name,
  table1.elemname as @ELEMENT2name,
  @ELEMENT1 / @ELEMENT2 as 'percentage'

This is a simplified snipit of the code I am trying to make more dynamic.
markros (Programmer)
21 May 09 15:37
If you want to format your columns certain way (make the names of the fields to match your variables), then you should construct the whole query as one string and execute it using execute statement.
03Explorer (TechnicalUser) (OP)
21 May 09 15:50
I am not certain on what you are saying... I want the column names to be resembling the field variables, but not as technical.

Can you share a simple example of what you are describing?
markros (Programmer)
21 May 09 17:32
DECLARE @StartDate DATETIME         SET @StartDate = '2009/01/01 00:00:00'
DECLARE @EndDate DATETIME           SET @EndDate   = '2009/05/20 23:59:59'
DECLARE @ELEMENT1name VARCHAR(100)     SET @ELEMENT1name = 'MemberID'
DECLARE @ELEMENT1 VARCHAR(100)         SET @ELEMENT1 = 'PatID_ValidIDPrompt'
DECLARE @ELEMENT2name VARCHAR(100)     SET @ELEMENT2name = 'Total_Calls'
DECLARE @ELEMENT2 VARCHAR(100)         SET @ELEMENT2 = 'PatID_Silencer'

declate @SqlStr varchar(4000)

  apname as ' + @application + ', table2.elemname as ' + @ELEMENT1name + ', table1.elemname as ' + @ELEMENT2name +
',' + @ELEMENT1 +'/'+ @ELEMENT2 + 'as '''percentage''' FROM '...
print @SqlStr -- to test

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Back To Forum

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close