Try the following code:
CREATE TABLE #Names
(
[Type] VARCHAR(50),
ColNum SMALLINT,
ColName VARCHAR(50),
ColDataType VARCHAR(20)
)
INSERT INTO #Names VALUES
('Customer', 1, 'CustomerID', 'INT'),
('Customer', 2, 'CustomerName', 'VARCHAR(50)'),
('Customer', 3, 'CustomerJoinDate', 'DATE'),
('Customer', 4, 'CustomerBirthDate', 'DATE'),
('Account', 1, 'AccountID', 'INT'),
('Account', 2, 'AccountName', 'VARCHAR(50)'),
('Account', 3, 'AccountOpenDate', 'DATE'),
('CustomerAccount', 1, 'CustomerID', 'INT'),
('CustomerAccount', 2, 'AccountID', 'INT'),
('CustomerAccount', 3, 'RelationshipSequence', 'TINYINT')
CREATE TABLE #Data
(
[Type] VARCHAR(50),
Col1 VARCHAR(50),
Col2 VARCHAR(50),
Col3 VARCHAR(50),
Col4 VARCHAR(50),
Col5 VARCHAR(50),
Col6 VARCHAR(50),
Col7 VARCHAR(50)
)
INSERT INTO #Data VALUES
('Customer', '1', 'Mr John Smith', '2005-05-20', '1980-11-15', NULL, NULL, NULL),
('Customer', '2', 'Mrs Hayley Jones', '2009-10-10', '1973-04-03', NULL, NULL, NULL),
('Customer', '3', 'ACME Manufacturing Ltd', '2012-12-01', NULL, NULL, NULL, NULL),
('Customer', '4', 'Mr Michael Crocker', '2014-01-13', '1957-01-23', NULL, NULL, NULL),
('Account', '1', 'Smith-Jones Cheque Acct', '2005-05-25', NULL, NULL, NULL, NULL),
('Account', '2', 'ACME Business Acct', '2012-12-01', NULL, NULL, NULL, NULL),
('Account', '3', 'ACME Social Club', '2013-02-10', NULL, NULL, NULL, NULL),
('Account', '4', 'Crocker Tipping Fund', '2014-01-14', NULL, NULL, NULL, NULL),
('CustomerAccount', '1', '1', '1', NULL, NULL, NULL, NULL),
('CustomerAccount', '2', '1', '2', NULL, NULL, NULL, NULL),
('CustomerAccount', '2', '3', '2', NULL, NULL, NULL, NULL),
('CustomerAccount', '3', '2', '1', NULL, NULL, NULL, NULL),
('CustomerAccount', '3', '3', '1', NULL, NULL, NULL, NULL),
('CustomerAccount', '4', '2', '2', NULL, NULL, NULL, NULL),
('CustomerAccount', '4', '4', '1', NULL, NULL, NULL, NULL)
DECLARE @Type VARCHAR(50) = 'Account' -- Or Customer, or CustomerAccount
DECLARE @SQLText NVARCHAR(MAX) = ''
SELECT @SQLText += 'SELECT '
SELECT @SQLText += ( -- Add in column list, with dynamic column names.
SELECT 'CONVERT(' + ColDataType + ', Col' + CONVERT(VARCHAR, ColNum) + ') AS [' + ColName + '],'
FROM #Names
WHERE [Type] = @Type FOR XML PATH('')
)
SELECT @SQLText = LEFT(@SQLText, LEN(@SQLText) - 1) + ' ' -- Remove trailing comma
SELECT @SQLText += 'FROM #Data WHERE [Type] = ''' + @Type + ''''
PRINT @SQLText
EXEC sp_executesql @SQLText
This returns the SELECT statement: SELECT CONVERT(INT, Col1) AS [AccountID],CONVERT(VARCHAR(50), Col2) AS [AccountName],CONVERT(DATE, Col3) AS [AccountOpenDate] FROM #Data WHERE [Type] = 'Account'
Best Answer
Given that this is an internal system table that you can only access when connecting via the DAC, no, there is no documentation on this. What are you using this table for?
I found several instances here where
rscolid
was not identical tohbcolid
. For example:Where does this row come from?
So what indexes might be involved?
So going on a guess, I ran this query:
One of the rows here:
So, without doing much more investigation, my initial guess is that
rscolid
is the column id within the base table, andhbcolid
is the ordinal position of that column in the index. This holds true for 5 of the columns in the clustered index of this queue table - they all have identical mismatches insys.sysrscols
, and also for one of the columns in the non-clustered index.But again, whether I'm right or wrong, I'm not sure what you could possibly do with that information: what are you using this table for?