Reputation: 33
If I get my time zone info from the registry into SQL, I get the full TZI data structure:
DECLARE @TzKey nvarchar(512)
Set @TzKey = 'SOFTWARE\Microsoft\Windows NT\CurrentVersion\Time Zones\Pacific Standard Time'
EXEC master.dbo.xp_regread 'HKEY_LOCAL_MACHINE', @TzKey, 'TZI'
it returns the full binary value
'0xE001000000000000C4FFFFFF00000B0000000100020000000000000000000300000002000200000000000000'
But, if I store it in a variable like this:
DECLARE @TzKey nvarchar(512)
DECLARE @TZI binary(85)
Set @TzKey = 'SOFTWARE\Microsoft\Windows NT\CurrentVersion\Time Zones\Pacific Standard Time'
EXEC master.dbo.xp_regread 'HKEY_LOCAL_MACHINE', @TzKey, 'TZI', @TZI OUTPUT
Then SELECT @TZI AS TzInfo
returns '0xE001'
I have tried every permutation of binary/varbinary and lengths (including MAX) that I can think of.
Any ideas?
Upvotes: 2
Views: 1095
Reputation: 239694
I'd do it using an INSERT ... EXEC
and then read the value back from the table the result is inserted into:
DECLARE @TzKey nvarchar(512)
DECLARE @TZI binary(85)
Set @TzKey = 'SOFTWARE\Microsoft\Windows NT\CurrentVersion\Time Zones\Pacific Standard Time'
declare @Results table (Value sysname,Data varbinary(300))
insert into @Results
EXEC master.dbo.xp_regread 'HKEY_LOCAL_MACHINE', @TzKey, 'TZI' --, @TZI OUTPUT
select @TZI = Data from @Results
(Insert usual caveats about using/relying upon undocumented procedures)
Upvotes: 2