Click here to Skip to main content
12,357,409 members (72,030 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: stored-procedure
Hi!
Please allow me to illustrate my question. I have a table called employee with the columns empid, last, first, mid, address and city. I've cloned this table to employeecl with the columns empid, last and first.
In my storeprocedure I want to select employeecl(empid,last,first) from employee so the next time I want to add a field to be selected in my SP I just have to add it in my clone table without anymore editing my SP, meaning columns that will be specified in my SP will depend on the columns available in the clone table which is also available in the source table. My cloned table does not contain values only fields. Do you think this is possible if so please help me I will use this in my project as I'm assigned to make our SPs dynamically.

Your help would be a great help.

Thank you!

In my question above iam using sql server 2005 actually i just want to make my stored procedure dynamic meaning i want to create select statement inside sp "Can i store fields in a table no records just fields and use that tablefields in my select statement?"
Posted 19-Sep-12 2:17am
Edited 19-Sep-12 15:27pm
v4
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

What you should do here is use the Create View[^] feature. In case you're not using a MS SQL DBMS flavor, this type of construct is supported by all major RDMBs.

Regards,

— Manfred
  Permalink  
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 2

for example

declare @mainquery varchar(max);
declare @subquery varchar(max);

set @subquery = 'name , address';
set @mainquery= 'select id,'+ cast(@subquery as varchar )+' from table' ;

exec sp_executesql @mainquery
  Permalink  
Comments
JOEY G. MOYA 21-Sep-12 1:16am
   
Think this solution would help me Thank you very much

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web02 | 2.8.160621.1 | Last Updated 20 Sep 2012
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100