星期三, 11月 23, 2011
ms sql 檢查資料表及資料表中的資料欄是否存在
在"資料表"的"欄位"存在,傳回1;"欄位"不存在,傳回0
select count(name) from syscolumns
where id=(
select id from sysobjects
where name='資料表名稱')
and name='欄位名稱'
判斷資料表存不存在
select * from doctor..sysobjects where name='病人' and type='U')
doctor is 資料庫名稱
病人是資料表的名稱
星期一, 5月 23, 2011
取得本地時間及utc時間
DECLARE @LocalDate DATETIME
SET @LocalDate = GETDATE()
-- convert local date to utc date
DECLARE @UTCDate DATETIME
SET @UTCDate = DATEADD(Hour, DATEDIFF(Hour, GETUTCDATE(), GETDATE()), @LocalDate)
-- convert utc date to local date
DECLARE @LocalDate2 DATETIME
SET @LocalDate2 = DATEADD(Hour, DATEDIFF(Hour, GETDATE(), GETUTCDATE()), @UTCDate)
SELECT @LocalDate, @UTCDate, @LocalDate2
SET @LocalDate = GETDATE()
-- convert local date to utc date
DECLARE @UTCDate DATETIME
SET @UTCDate = DATEADD(Hour, DATEDIFF(Hour, GETUTCDATE(), GETDATE()), @LocalDate)
-- convert utc date to local date
DECLARE @LocalDate2 DATETIME
SET @LocalDate2 = DATEADD(Hour, DATEDIFF(Hour, GETDATE(), GETUTCDATE()), @UTCDate)
SELECT @LocalDate, @UTCDate, @LocalDate2
星期五, 5月 07, 2010
使用stuff將多筆記錄合併成一筆並用逗號分隔
select stuff((select ','+user_name From im_chat_log where id in (1, 2) FOR XML PATH('')),1,1,'' ) as xylist
訂閱:
文章 (Atom)