docstar
asked on
Need to obtain a single XML String for a set of tables
I am attempting to convert our current data schema from having "Custom Field" data in multiple tables to a single field. The problem I have is that these multiple tables are not statically named. Here is an example
CUSTOMER 1: Has 4 custom fields so there are 5 tables involved:
Customfields - id, field name, table name, field type
cf_InvoiceNum - id, docID, lValue
cf_CheckNum - id, docID, lValue
cf_CheckDate - id, docID, dtValue
cf_CustName - id, docID, sValue
CUSTOMER 2: Has 2 Custom fields so there are 3 tables involved:
Customfields - id, field name, table name, field type
cf_MLSNum - id, docID, lValue
cf_SaleStatus - id, docID, sValue
The Customfields table is static and will be present on all systems, it contains the table names of the custom fields. The ultimate goal is to get All of the data per docID in each of the customfield tabled into a single XML string that defined the field name, Value (l (int), s (string), or dt (datetime)), and datatype.
In customer 2's case it would be something like
<CustomFields>
<MLSNumber>
<Value>123456</Value>
<DataType>Int</DataType>
</MLSNumber>
<MLSNumber>
<Value>222222</Value>
<DataType>Int</DataType>
</MLSNumber>
<SalesStatus>
<Value>Sale Pending</Value>
<DataType>Varchar(40)</Dat aType>
</SalesStatus>
</CustomFields>
the above would be per docID. The main problem I am having is how do I create a function that can take a docID and find all of its customfield values and return a single XML string when the table names are not static, the are stored in a table but do I have to implement a cursor to do a dynamic sql for each row returned in the cursor? It can be done just seems wrong.
CUSTOMER 1: Has 4 custom fields so there are 5 tables involved:
Customfields - id, field name, table name, field type
cf_InvoiceNum - id, docID, lValue
cf_CheckNum - id, docID, lValue
cf_CheckDate - id, docID, dtValue
cf_CustName - id, docID, sValue
CUSTOMER 2: Has 2 Custom fields so there are 3 tables involved:
Customfields - id, field name, table name, field type
cf_MLSNum - id, docID, lValue
cf_SaleStatus - id, docID, sValue
The Customfields table is static and will be present on all systems, it contains the table names of the custom fields. The ultimate goal is to get All of the data per docID in each of the customfield tabled into a single XML string that defined the field name, Value (l (int), s (string), or dt (datetime)), and datatype.
In customer 2's case it would be something like
<CustomFields>
<MLSNumber>
<Value>123456</Value>
<DataType>Int</DataType>
</MLSNumber>
<MLSNumber>
<Value>222222</Value>
<DataType>Int</DataType>
</MLSNumber>
<SalesStatus>
<Value>Sale Pending</Value>
<DataType>Varchar(40)</Dat
</SalesStatus>
</CustomFields>
the above would be per docID. The main problem I am having is how do I create a function that can take a docID and find all of its customfield values and return a single XML string when the table names are not static, the are stored in a table but do I have to implement a cursor to do a dynamic sql for each row returned in the cursor? It can be done just seems wrong.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Open in new window