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 can I write Query based of dynamic column?

Author  Topic 

GautamRy
Starting Member

2 Posts

Posted - 2010-11-23 : 10:14:58
Hi
I am trying to write a query on the following tables.
My tables are as below

TABLE : tblcases

cs_cid | cs_pr_pid |
======================================================
2589327 | 35 |
6965345 | 37 |
6965349 | 39 |
====================================================

TABLE : tblProcess

pr_pid | pr_name
====================================================
35 | prod_test
37 | prod_test5
39 | prod_test9
=================================================

TABLE tblidProcessmapping

idmp_imid | idmp_pr_pid | idmp_idname | idmp_name
======================================================
1 35 csext_id1 REFERENCE No
2 35 csext_id10 PolicyNumber
3 37 csext_id9 REFERENCE No
4 37 csext_id19 PolicyNumber
5 39 csext_id21 REFERENCE No
6 39 csext_id22 PolicyNumber
================================================================

TABLE : tblcasecustomattributes

csext_cs_cid csext_id1 csext_id2 csext_id9 csext_id10 . ..
================================================================== 2589327 10 NULL Null 123456
6965345 NULL NULL NULL 89000

Now, I need to write a QUERY where I shall pass cs_cid and 'REFERENCE No' as input parameter and in return I shall be able to get realted value (In this case 10)

Please,suggest me How i can approach

Regards
Gautam

bobmcclellan
Starting Member

46 Posts

Posted - 2010-11-23 : 11:16:00
Erland's post on The Curse and Blessings of Dynamic SQL
addresses this.
http://www.sommarskog.se/dynamic_sql.html
Go to Top of Page
   

- Advertisement -