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)
 How to add dynamic field into sp.

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2005-09-14 : 06:54:48
Mark writes "Hi,

I have table that have dynamic field from other table.

id Date Category FieldValue FieldName
1 09/06/2005 Agency QW12 Bill
3 09/06/2005 Agency 12 Time
5 09/06/2005 Agency OK Dynamic

I can convert it into one row,by using query.

SELECT Date,Category,Max(Bill) Bill,Max(Time)Time,
Max(Dynamic) Dynamic from (Select Date, Category
(CASE WHEN FieldName='Bill'then Max(FieldValue) END) Bill,
(CASE WHEN FieldName='Time' then Max(FieldValue) END) Time,
(CASE WHEN FieldName='Dynamic'then Max(FieldValue)END) Dynamic
from Table1 group by Date,Category) A Group by Date,Category

Date Category Bill Time Dynamic
09/06/05 Agency QW12 12 OK

How to instead of data in FieldName use veriable?
In this case I can pick any dynamic field and display"

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2005-09-14 : 07:17:46
There is no need of Dynamic SQL
You need to refer this
http://sqljunkies.com/WebLog/amachanic/archive/2004/11/10/5065.aspx?Pending=true

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -