I'm in the process of transferring lots of embedded SQL in some SSRS reports to functions. The process generally involves taking the current select query, adding an INSERT INTO part and returning a results table. Something like this:
CREATE FUNCTION [dbo].[MyReportFunction]
(
@userid varchar(255),
@location varchar(255),
more params here...
)
RETURNS @Results TABLE
(
Title nvarchar(max),
Location nvarchar(255),
more columns here...
)
AS
BEGIN
INSERT INTO @Results (Title, Location, more columns...)
SELECT tblA.Title, tblB.Location, more columns...
FROM TableA tblA
INNER JOIN TableB tblB
ON tblA.Id = tblB.Id
WHERE tblB.Location = @location
RETURN
END
As part of this I have to put the columns into the @Results table and give them the correct size and type as per what's returned from the SELECT query. Now getting the type is fine as I can just copy and paste the existing SELECT query into a new query and mouse over the column name to get that e.g. column Title (nvarchar, null). However, I also need to know the size. Is there an easy way of doing that without having to go to the particular tables and looking at the column list? Is there perhaps a way of editing the tooltip and the information it displays on mouse over?
If I've got a lot of joins to different tables and a long list of tables to scroll through this can get tiresome.
I'm using SQL Server 2008 R2