小的在写sql语句时发现的问题 有点奇怪了 请各位看看create procedure ww
@a smalldatetime
as
begin
declare @b nvarchar(1024)
set @b = 'select * from UsersNote where UClock < ''' + @a + ''''
exec sp_executeSQL @b
endexec ww '2000-01-01'报错为 将字符串转换为 smalldatetime 数据类型时失败。可是如果直接执行sql语句就没事 --原方式代码如下
create procedure ww
@a smalldatetime
as
begin
select * from UsersNote where UClock < @a endexec ww '2000-01-01'
郁闷了 哪位能给看看 先谢过了
@a smalldatetime
as
begin
declare @b nvarchar(1024)
set @b = 'select * from UsersNote where UClock < ''' + @a + ''''
exec sp_executeSQL @b
endexec ww '2000-01-01'报错为 将字符串转换为 smalldatetime 数据类型时失败。可是如果直接执行sql语句就没事 --原方式代码如下
create procedure ww
@a smalldatetime
as
begin
select * from UsersNote where UClock < @a endexec ww '2000-01-01'
郁闷了 哪位能给看看 先谢过了
@a smalldatetime
as
begin
declare @b nvarchar(1024)
set @b = 'select * from UsersNote where UClock < ''' + convert(char(10),@a,120) + ''''
exec(@b)
end
@a smalldatetime
as
begin
declare @b nvarchar(1024)
set @b = 'select * from UsersNote where UClock < ''' + convert(varchar,@a,121) + ''''
exec sp_executeSQL @b
end
再做的过程中发现了这个问题 搞了半天了 没弄明白望大人指点一二
语言的通性. 两种不同类型的数据进行操作时,系统为了避免精度损失,总是想尝试把精度低的的类型转换为精度高的类型再一起运算.所以 @s + @d 不是字串连,而是 datetiime +接下来再看这个.DECLARE @d DATETIME ,@s VARCHAR(10)
SET @d=GETDATE()
SET @s='2001-1-1'
SELECT @d+@s