tsql - Procedure from Firebird to SQL Server -
tsql - Procedure from Firebird to SQL Server -
i need create stored-procedure returns 1 row every week between 2 dates. create procedure in firebird, can't accomplish same thing in sql server 2012.
i seek utilize stored-procedure, cannot called select statement (i need utilize result in union query)
i seek utilize function, homecoming 1 (last) value (week).
how can rewrite stored procedure sql server 2012?
begin tydent = startdate; while (tydent < enddate) begin select first 1 extract(year cast(ib_datetostring(:tydent, 'dd.mm.yyyy') date)), extract(week cast(ib_datetostring(:tydent, 'dd.mm.yyyy') date)) securityusers :rok, :tyden begin suspend; end tydent = tydent + 7; end end
startdate
, enddate
input parameters. rok
, tyden
output paramaters , tydent
variable.
edit. if utilize (41952 , 41975 date in float)
select * storedprocedure(41952, 41975)
then want get:
you utilize user-defined function this.
this example, can written better, should given thought hope. used strings input dates i'm not sure how convert float dates (which guess firebird or delphi thing).
create function dbo.getweeknumbers (@startdate date, @enddate date) returns table homecoming ( cte (d) ( select dateadd(day, 1, @startdate) d union select dateadd(day, 1, d) cte d < @enddate ) select distinct datepart(year, d) y, datepart(week, d) w cte );
and phone call this:
select * dbo.getweeknumbers('2014-10-01','2014-10-20')
result:
y w ----------- ----------- 2014 40 2014 41 2014 42 2014 43
sql-server tsql stored-procedures sql-server-2012 firebird
Comments
Post a Comment