SQL에서 다음 코드를 수행합니다. 인쇄 섹션이 실행되면 'Dec 31 2050 11:59 PM'이 반환됩니다. 나는 코드의 나머지 부분에서 변수를 사용하고 (표시되지 않음) 작동하지 않으며 "문자열을 smalldatetime 데이터 유형으로 변환 할 때 변환이 실패했습니다"라는 오류가 발생합니다.datetime 변수 설정
형식을 혼동 시켰습니까? 나는 datetime이 'yyyy-mm-dd hh : mm : ss'로 끝났다고 생각했지만 분명히 틀림없이 틀렸다. datetim 형식을 보는 모든 곳에서 이것이 작동해야한다고 말합니다. 그래서 내가 뭘 잘못하고 있는지 모르겠습니다.
declare @date int
[email protected] is yyyymm format
declare @sql_v_fx as varchar(max), @sql_dim_for_exc as varchar(max)
declare @maxEndDate as smalldatetime
set @date = 201202
set @maxEndDate = Convert(smalldatetime, '2050-12-31 23:59', 101)
print @maxenddate
--remove prior date in [zstbl_fx_rollback]
truncate table zstbl_fx_rollback
--insert the user entered month
--specify in the VS report whether it's Balance Sheet or Income Statement date
insert into [zstbl_fx_rollback] (yyyymm) select @date
--alter the v_fx view to into account the date in the [zstbl_fx_rollback] table
select @sql_v_fx =
'
Alter view [dbo].[v_fx] as
select
[foreign exchange key],[currency key], [to usd], [from usd], [effective date],
[expiration date] =
case when [effective date] =
convert(datetime,cast((select isnull(max(yyyymm),205012) from zstbl_fx_rollback) * 100 + 1 as char(8))) then ' + @maxEndDate + ' else [expiration date] end
,[is current]
,[effective date key] = year([effective date]) * 10000 + month([effective date])*100
from crs..[dim foreign exchange]
where [effective date] <= convert(datetime,cast((select isnull(max(yyyymm),205012) from zstbl_fx_rollback) * 100 + 1 as char(8)))
'
exec(@sql_v_fx)
을 확인? 나는이 코드에 아무런 문제가 보이지 않는다. – Sean
예이 코드는 작동해야합니다.이 오류가 발생한 곳의 코드를 게시 할 수 있습니까? 내가 이것을 실행하고 나는 어떤 에러도 내지 않는다. 'SELECT 1 WHERE @maxEndDate> GETDATE()','SELECT 1 WHERE CAST (@maxEndDate as smalldatetime)> GETDATE()' –
이것을 할 수 없다. '2050-12-31 23:59:00'* 10000> GETDATE()'varchar 날짜 문자열에 10000을 곱하십시오. –