Monday, December 30, 2013

How to create a function to output Any recordset into JSON format?

I want to create a T-SQL function,to output "ANY" recordset into JSON format.That means,this function needs two parameters,the first is the recordset and the second is output json parametername.For example,I got a recordset with three columns("fieldA","fieldB","fieldC") and two rows("1","2","3";"a","b","c"),thus the function should output the json string like "datalist":[{"fieldA":"1","fieldB":"2","fieldC":"3"},{"fieldA":"a","fieldB":"b","fieldC":"c"}]("datalist" is the parametername).


Now the question:


1,How to pass a recordset as a parameter to a function?especially the recordset does NOT have a certain structure.


2,How could I get the structure(fields and their datatypes) from any recordset Such as a select sql?


Thanks


No comments:

Post a Comment