반응형
반응형

[mssql]  숫자 앞에 0 으로 채우기, Replicate

 


-- 2013-9-2
select YEAR(getDate()), Month(getdate()), day(getdate())


-- 2013-09-02
select YEAR(getDate()), replicate('0',2 - len(Month(getdate()))) + cast(Month(getdate()) as varchar), replicate('0',2 - len(day(getdate()))) + cast(day(getdate()) as varchar)

반응형
반응형

 

-- 임시테이블명 : #mytemptable'

 IF OBJECT_ID('tempdb..#mytemptable') is not null

      select * from #mytemptable'with(nolock)

 

SELECT OBJECT_ID('tempdb..#mytemptable')

 

 

스키마 범위 개체의 데이터베이스 개체 ID를 반환합니다.

반응형
반응형

--Getdate()
Select Getdate()

 

--YYYY/MM/DD
Select Convert(varchar(10),Getdate(),111)

 

--YYYYMMDD
Select Convert(varchar(10),Getdate(),112)

 

--HH:MM:SS
Select Convert(varchar(8),Getdate(),108)

 

--HH:MM:SS:mmm
Select Convert(varchar(12),Getdate(),114)

 

--HHMMSS
Select Replace(Convert(varchar(8),Getdate(),108),':','')

 

--HHMMSSmmm
Select Replace(Convert(varchar(12),Getdate(),114),':','')

 

--YYYY/MM/DD HH:MM:SS
Select Replace(Convert(varchar(30),Getdate(),120),'-','/')

 

--YYYY/MM/DD HH:MM:SS
Select Replace(Convert(varchar(30),Getdate(),121),'-','/')

 

--YYYY/MM/DD HH:MM:SS
Select Convert(varchar(10),Getdate(),111) + Space(1) + Convert(varchar(8),Getdate(),108)

 

--YYYYMMDDHHMMSS
Select Convert(varchar(10),Getdate(),112) + Replace(Convert(varchar(8),Getdate(),108),':','')

 

반응형

+ Recent posts