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 2005 Forums
 Transact-SQL (2005)
 how to fetch data of column name that comes table

Author  Topic 

imranabdulaziz
Yak Posting Veteran

83 Posts

Posted - 2009-03-20 : 07:22:23
Dear All,
I am using sql server 2005.
My requirement is given date and month. Make date and compare it from today and find the diffence if difference is below 7 show the perticular detail.

My problem is I have a table(Event_attribute) from where I come to know which field of main table(Customer_attributes) to search on Which is as

Event_attribute

Eventid Dd field Mm field
1 Ca_dd_dob Ca_mm_dob
2 Ca_dd_doa Ca_mm_doa

This ca_dd_dob , ca_mm_dob , ca_dd_doa , ca_mm_doa are field of another table customer_attributes
Doctor Ca_dd_dob Ca_mm_dob Ca_dd_doa Ca_dd_doa
D00045 20 2 15 5


Now when I run the query
SELECT (SELECT DD_field FROM CMS_EVENT_ATT_REL WHERE EAR_EVENTID = 1) FROM CMS_CUSTOMER_ATTRIBUTES

It returns me ca_dd_dob rather then returning 20. I tried with dynamic query it show me datatype mismatch as it also return ca_dd_dob


Please suggest

matty
Posting Yak Master

161 Posts

Posted - 2009-03-20 : 07:35:16
Use Dynamic SQL
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2009-03-20 : 08:33:21
www.sommarskog.se/dynamic_sql.html


Madhivanan

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

- Advertisement -