Using TagValueList

TagValueList builds a series of name/value pairs and returns the string in @List. Test the procedure in whatever version of SQL Server you are running. Certain datatypes have to be converted to strings explicitly, and that list changes by version.

Note that a NULL passed to TagValueList will print the string 'NULL' in the output.

Find the code for TagValueList here.

Example

Call

DECLARE @RegionID           int;
DECLARE @RegionDescription  char(50);
DECLARE @errorMsg           varchar(512);

SELECT
    @RegionID          = 12345,
    @RegionDescription = 'Pacific Northwest';

EXEC dbo.TagValueList
        @errorMsg OUTPUT,
        N'RegionID', @RegionID,
        N'RegionDescription', @RegionDescription;

Result

Value of @errorMsg:

(RegionID: 12345) (RegionDescription: Pacific Northwest)