Thursday, March 8, 2012

CALL STORED PROCEDURE IN MY QUERY

I have a stored procedure to calculate difference days between 2 days
excluding wend like following
CREATE PROCEDURE Busdays @.from_dt datetime,@.to_dt datetime ,@.wkends int
output
AS
DECLARE
@.days int,
@.dp int ,
@.cnt int
set @.wkends=0
set @.cnt=0
set @.days=datediff(d,@.FROM_DT,@.TO_DT)
while @.cnt <=@.days
begin
set @.dp=datepart(dw,dateadd(day,@.cnt,@.FROM_D
T))
if @.dp<>1 AND @.dp<>7
set @.wkends=@.wkends+1
set @.cnt=@.cnt+1
END
GO
I would like to pass 2 dates field to this stored procedure to get result
in my query like following
DECLARE @.MYDATE INT
SELECT ACCOUNT_NUMBER, [PROCESS DATE], [OPENED DATE],
EXEC BUSDAYS [PROCESS DATE], [OPENED DATE], @.MYDATE OUTPUT FROM MYTABLE
following SQL is working:
DECLARE @.MYDATE INT
EXEC BUSDAYS '3/20/2005', '3/30/2005', @.MYDATE OUTPUT
SELECT @.MYDATE AS 'MYDATE'
Is it possible to do this?
Where I did wrong here?
May I get return value in my query?
Any information is great appreciated,
Souris,souris
DECLARE @.MYDATE INT
EXEC BUSDAYS '3/20/2005', '3/30/2005', @.MYDATE OUTPUT
SELECT ACCOUNT_NUMBER, [PROCESS DATE], [OPENED DATE],@.mayDate FROM Tabel
"souris" <soukkris@.viddotron.com> wrote in message
news:e4nq6MbNFHA.2612@.TK2MSFTNGP10.phx.gbl...
> I have a stored procedure to calculate difference days between 2 days
> excluding wend like following
> CREATE PROCEDURE Busdays @.from_dt datetime,@.to_dt datetime ,@.wkends int
> output
> AS
> DECLARE
> @.days int,
> @.dp int ,
> @.cnt int
> set @.wkends=0
> set @.cnt=0
> set @.days=datediff(d,@.FROM_DT,@.TO_DT)
> while @.cnt <=@.days
> begin
> set @.dp=datepart(dw,dateadd(day,@.cnt,@.FROM_D
T))
> if @.dp<>1 AND @.dp<>7
> set @.wkends=@.wkends+1
> set @.cnt=@.cnt+1
> END
> GO
>
> I would like to pass 2 dates field to this stored procedure to get result
> in my query like following
> DECLARE @.MYDATE INT
> SELECT ACCOUNT_NUMBER, [PROCESS DATE], [OPENED DATE],
> EXEC BUSDAYS [PROCESS DATE], [OPENED DATE], @.MYDATE OUTPUT FROM MYTABLE
> following SQL is working:
> DECLARE @.MYDATE INT
> EXEC BUSDAYS '3/20/2005', '3/30/2005', @.MYDATE OUTPUT
> SELECT @.MYDATE AS 'MYDATE'
>
> Is it possible to do this?
> Where I did wrong here?
> May I get return value in my query?
> Any information is great appreciated,
> Souris,
>
>
>

No comments:

Post a Comment