如何在SQL Server 2008中设置datetime变量

时间:2014-03-21 09:48:33

标签: sql-server-2008

declare @test as DATETIME

set @test='21/03/2014'

print @test

select @test

set @test=21/03/2014

print @test

select @test

set @test=21-03-2014

print @test

select @test

set @test=03/21/2014

print @test

select @test

set @test=2014/21/03

print @test

select @test

set @test=2014/03/21

print @test

select @test

此代码提供了错误的输出,因此请告诉我在SQLServer 2008中分配datetime变量的代码

1 个答案:

答案 0 :(得分:6)

declare @test datetime

set @test='03/21/2014'

//set @test='21/03/2014' This is not valid you must give date in MM/dd/yyyy

print @test



set @test='2014/03/21'

print @test