От MS-овского SQL-я - к галактическому
Добавлено: 19 окт 2005, 13:17
Нужно перевести SQL конструкцию на галактичекий язык
Подскажите плз - где и что нужно подправить (реализовать это в create view):
CREATE FUNCTION IntToDate(@S integer)
RETURNS varchar(10) AS
BEGIN
declare
@dt varchar(10),
@ret varchar(10)
set @dt=
convert(varchar,convert(int,substring(convert(BINARY(4),@s),4,1)))+'.'+
convert(varchar,convert(int,substring(convert(BINARY(4),@s),3,1)))+'.'+
convert(varchar,convert(int,substring(convert(BINARY(4),@s),1,2)))
set @ret=
case
when isdate(@dt)=1 then @dt
else null
end
RETURN @ret
END
drop table #db1
select
convert(int,f$tipsopr) as dvig
,f$cstepdoc as dst
,dbo.inttodate(k.f$dsopr) as kdats
,dbo.inttodate(k.f$dopr) as kdato
,k.f$name as kname,
k.f$summa as ksum,
k.f$nsopr as kdoc
into #db1
from t$katsopr k
where
convert(datetime,dbo.inttodate(k.f$dsopr))>=convert(datetime,'1.1.2005')
and convert(datetime,dbo.inttodate(k.f$dsopr))<=convert(datetime,'1.11.2005')
and f$tipsopr in(1,2)
and k.f$dopr<>0
and k.f$corg=
--0x8001000000003F0B
0x8001000000004440
insert into #db1
select
convert(int,f$direct)
as dvig
,f$cstepdoc as dst
,dbo.inttodate(b.f$ddoc) as kdats
,dbo.inttodate(b.f$ddoc) as kdato
,b.f$namepl as bname
,b.f$summa as ksum
,b.f$nodoc as pdoc
from t$basefin b
convert(datetime,dbo.inttodate(k.f$ddoc))>=convert(datetime,'1.1.2005')
and convert(datetime,dbo.inttodate(k.f$ddoc))<=convert(datetime,'1.11.2005')
and f$direct in(1,2)
and b.f$summa<>0
and b.f$tidkgal<=9
and b.f$corg=
--0x8001000000003F0B
0x8001000000004440
select *
--sum(ksum) ,dvig
from #db1
--group by dvig
order by dst,dvig
Подскажите плз - где и что нужно подправить (реализовать это в create view):
CREATE FUNCTION IntToDate(@S integer)
RETURNS varchar(10) AS
BEGIN
declare
@dt varchar(10),
@ret varchar(10)
set @dt=
convert(varchar,convert(int,substring(convert(BINARY(4),@s),4,1)))+'.'+
convert(varchar,convert(int,substring(convert(BINARY(4),@s),3,1)))+'.'+
convert(varchar,convert(int,substring(convert(BINARY(4),@s),1,2)))
set @ret=
case
when isdate(@dt)=1 then @dt
else null
end
RETURN @ret
END
drop table #db1
select
convert(int,f$tipsopr) as dvig
,f$cstepdoc as dst
,dbo.inttodate(k.f$dsopr) as kdats
,dbo.inttodate(k.f$dopr) as kdato
,k.f$name as kname,
k.f$summa as ksum,
k.f$nsopr as kdoc
into #db1
from t$katsopr k
where
convert(datetime,dbo.inttodate(k.f$dsopr))>=convert(datetime,'1.1.2005')
and convert(datetime,dbo.inttodate(k.f$dsopr))<=convert(datetime,'1.11.2005')
and f$tipsopr in(1,2)
and k.f$dopr<>0
and k.f$corg=
--0x8001000000003F0B
0x8001000000004440
insert into #db1
select
convert(int,f$direct)
as dvig
,f$cstepdoc as dst
,dbo.inttodate(b.f$ddoc) as kdats
,dbo.inttodate(b.f$ddoc) as kdato
,b.f$namepl as bname
,b.f$summa as ksum
,b.f$nodoc as pdoc
from t$basefin b
convert(datetime,dbo.inttodate(k.f$ddoc))>=convert(datetime,'1.1.2005')
and convert(datetime,dbo.inttodate(k.f$ddoc))<=convert(datetime,'1.11.2005')
and f$direct in(1,2)
and b.f$summa<>0
and b.f$tidkgal<=9
and b.f$corg=
--0x8001000000003F0B
0x8001000000004440
select *
--sum(ksum) ,dvig
from #db1
--group by dvig
order by dst,dvig