Here's a little script I use to generate SQL statements for selecting rows from a UDT.
You will need to know the ModuleID of your UDT. Paste the script given below into your Host SQL page.
Replace the ModuleID (461) with the ModuleID of your UDT.
Run the script and the output will be a SQL SELECT statement you can use in the reportsmodule.
If you want to project, restrict or aggregate the results you can create a view in the database and then select from that view in the reports module:
"CREATE VIEW MyView AS <generated select goes here>"
then you can SELECT * FROM MyView like it was a normal table.
The script:
DECLARE @UDT_ModuleId int
SET @UDT_ModuleId=461
SELECT 'SELECT {databaseOwner}{objectQualifier}UserDefinedRows.UserDefinedRowId AS Id' +
( SELECT ' ,['+ udt2.FieldTitle +'].FieldValue AS ['+udt2.FieldTitle+']'
FROM {databaseOwner}{objectQualifier}UserDefinedFields udt2
WHERE udt2.ModuleID = udt1.ModuleID AND udt2.Visible <> 0 AND udt2.ModuleID=@UDT_ModuleId
ORDER BY FieldOrder
FOR XML PATH('') )
+ ' FROM {databaseOwner}{objectQualifier}UserDefinedRows ' +
(SELECT ' LEFT OUTER JOIN {databaseOwner}{objectQualifier}UserDefinedData AS ['
+ {databaseOwner}{objectQualifier}UserDefinedFields.FieldTitle
+'] ON {databaseOwner}{objectQualifier}UserDefinedRows.UserDefinedRowId = ['
+{databaseOwner}{objectQualifier}UserDefinedFields.FieldTitle+'].UserDefinedRowId AND ['
+{databaseOwner}{objectQualifier}UserDefinedFields.FieldTitle+'].UserDefinedFieldId='
+CAST({databaseOwner}{objectQualifier}UserDefinedFields.UserDefinedFieldId as nvarchar)
FROM {databaseOwner}{objectQualifier}UserDefinedFields
INNER JOIN {databaseOwner}{objectQualifier}Modules
ON ({databaseOwner}{objectQualifier}UserDefinedFields.ModuleId={databaseOwner}{objectQualifier}Modules.ModuleId)
WHERE {databaseOwner}{objectQualifier}UserDefinedFields.ModuleId=@UDT_ModuleId
AND {databaseOwner}{objectQualifier}UserDefinedFields.Visible<>0
ORDER BY FieldOrder FOR XML PATH('') )
+ ' WHERE {databaseOwner}{objectQualifier}UserDefinedRows.ModuleId = ' + CAST(@UDT_ModuleId as nvarchar)
AS UdtSql
FROM {databaseOwner}{objectQualifier}UserDefinedFields udt1
GROUP BY ModuleId
HAVING ModuleID=@UDT_ModuleId