2015-04-02 115 views
0

我有一個用戶文化的用戶表。我需要從時間文化中獲得時間。參考請查看下錶。獲取時間格式的時區列

  UserCulture 
------------------------------------------ 
(UTC-12:00) International Date Line West 
(UTC-08:00) Baja California 
(UTC+05:30) Chennai, Kolkata, Mumbai, New Delhi 
(UTC+08:00) Kuala Lumpur, Singapore 
(UTC+08:00) Kuala Lumpur, Singapore 
(UTC+08:00) Kuala Lumpur, Singapore 
(UTC+08:00) Kuala Lumpur, Singapore 
(UTC+08:00) Kuala Lumpur, Singapore 
(UTC+08:00) Kuala Lumpur, Singapore 
(UTC+08:00) Kuala Lumpur, Singapore 
(UTC+08:00) Kuala Lumpur, Singapore 

我想出來放 「+8:00」 如果是吉隆坡,新加坡

+0

它是一列還是用逗號分隔的值? – 2015-04-02 07:29:15

回答

1

如果這僅僅是一個varchar列,那麼這可以工作:

DECLARE @t TABLE(TimeZone NVARCHAR(max)) 

INSERT INTO @t VALUES 
('(UTC-12:00) International Date Line West'), 
('(UTC-08:00) Baja California'), 
('(UTC+05:30) Chennai, Kolkata, Mumbai, New Delhi'), 
('(UTC+08:00) Kuala Lumpur, Singapore') 


SELECT TimeZone, SUBSTRING(timezone, 5, 6) AS Time FROM @t 

輸出:

TimeZone           Time 
(UTC-12:00) International Date Line West   -12:00 
(UTC-08:00) Baja California      -08:00 
(UTC+05:30) Chennai, Kolkata, Mumbai, New Delhi +05:30 
(UTC+08:00) Kuala Lumpur, Singapore    +08:00