Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 dynamic col name in a SP based on passed interger

Author  Topic 

genic
Yak Posting Veteran

57 Posts

Posted - 2002-05-20 : 15:45:12
this is what i am trying to do

36 questions have been answered with all answers going into one row. this results in 37 col's (autoID). each col has a set number. i am trying to do this within a store procedure. i added my comment below within the code under the question area. its a simple sp temp table, however i have 36 questions with 7 different options.

ideas?


CREATE PROCEDURE sp_select_self
(@nomid nvarchar(50),
@question int)
AS

CREATE TABLE #tempStrong_Agree
(
nomid nvarchar(50),
total nvarchar(100),
)

INSERT INTO #tempStrong_agree (nomid, total)
SELECT nomid, count(*) FROM Assessments where nomid=@nomid and assessor_relationship like '%Self%' and question1=6

/**
note the 'question' field name above in the select statement.
each 'question' field name will be question1..question36.
i need a way to use the @question interger passed to the
SP to determine the col to select from
**/


select * from #tempStrong_agree
GO



is this doable? i cant use the @question to pass the select statement what colum we are on.

Page47
Master Smack Fu Yak Hacker

2878 Posts

Posted - 2002-05-20 : 15:51:18
quote:
is this doable? i cant use the @question to pass the select statement what colum we are on.


Not quite, you will have to use dynamic SQL. However, I would suggest you take another look at your table design.

<O>
Go to Top of Page
   

- Advertisement -