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
 Transact-SQL (2000)
 How to select column dynamically

Author  Topic 

jigneshsoni
Starting Member

1 Post

Posted - 2005-09-02 : 00:42:55
hello guys, i am new to sql server,
i have one query in procedure, i want to select fields in a select query, but among them one field comes dynamically depends on the value of the record.

my structure is like this
i have two tables clients and misc,
misc table contains few client names in one column and another column contains one field name of client table like

client1 date1
client2 date1
client3 date2
etc...

now while displaying clients in a select query, if client is client1 then i want to display second field value from date1, if client is client2 then again i want to display second field value as date1 but client is client3 then i want second field's value as date2 in select query.
client table;s structure is like this..

client date1 date2 date3
client1 date11 date12 date13
client2 date21 date22 date23
client3 date31 date32 date33

and i want outout like this in select query

client misc_date
client1 date11
client2 date21
client3 date32

please help me to solve this procedure

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2005-09-02 : 01:17:13
Not sure whether this is what you wanted

Select Client, Case when Client='Client1' then Date1 else Date2 end as misc_date
from yourTable

Otherwise post some sample data and the result you want


Madhivanan

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

- Advertisement -