Showing posts with label intset. Show all posts
Showing posts with label intset. Show all posts

Wednesday, March 7, 2012

Call stored procedure from another stored procedure?

How do I call this stored procedure:

CREATE Procedure hentSpecialPris
(
@.varenr int,
@.cvr int,
@.pris decimal(7,2) OUTPUT
)

AS

DECLARE @.antal int

SET @.antal = 0

SET @.antal = (SELECT COUNT(*) FROM rabat WHERE varenr=@.varenr and cvr = @.cvr)

IF @.antal < 1
BEGIN
SET @.pris = (SELECT pris FROM vare WHERE varenr=@.varenr)
END

ELSE
BEGIN
SET @.pris = (SELECT pris FROM rabat WHERE varenr=@.varenr and cvr = @.cvr)
END

GO

from another stored procedure?? I want to get the output value of the stored procedure?


CREATE PROCEDURE OtherProc @.varent int,@.cvr int
AS

DECLARE @.pris decimal(7,2)

EXEC hentSpecialPris @.varent,@.cvt,@.pris OUTPUT

GO

You could also make this SP a user defined funciton, if it will always be called from another SP.

Tuesday, February 14, 2012

Calculating last date of the month

Given:
DECLARE @.AnalysisMonth int
DECLARE @.EndingDate int
SET @.AnalysisMonth = 1
How do I set the @.EndingDate variable to 31, i.e. the first month (1,
January) has 31 days?Starting with a date to get the last day of the month:
declare @.d datetime
set @.d = '29 Jan 2006'
select dateadd(day,-datepart(day, dateadd(month,1,@.d)),
dateadd(month,1,@.d))
2006-01-31 00:00:00.000
What this does is jump ahead one month, then back as many days as that
day of the month.
Roy Harvey
Beacon Falls, CT
On Tue, 28 Feb 2006 17:50:06 -0700, "Terri" <terri@.cybernets.com>
wrote:

>Given:
>DECLARE @.AnalysisMonth int
>DECLARE @.EndingDate int
>SET @.AnalysisMonth = 1
>How do I set the @.EndingDate variable to 31, i.e. the first month (1,
>January) has 31 days?|||Just start with the first day of the month and subtract a day and see what
it is.|||Terri
SELECT DATEADD(month,DATEDIFF(month,'19000101',
GETDATE()),'19000101')-1
"Terri" <terri@.cybernets.com> wrote in message
news:du2r3v$8sv$1@.reader2.nmix.net...
> Given:
> DECLARE @.AnalysisMonth int
> DECLARE @.EndingDate int
> SET @.AnalysisMonth = 1
> How do I set the @.EndingDate variable to 31, i.e. the first month (1,
> January) has 31 days?
>
>
>
>|||I like this.
malcolm
"Roy Harvey" wrote:

> Starting with a date to get the last day of the month:
> declare @.d datetime
> set @.d = '29 Jan 2006'
> select dateadd(day,-datepart(day, dateadd(month,1,@.d)),
> dateadd(month,1,@.d))
> --
> 2006-01-31 00:00:00.000
> What this does is jump ahead one month, then back as many days as that
> day of the month.
> Roy Harvey
> Beacon Falls, CT
> On Tue, 28 Feb 2006 17:50:06 -0700, "Terri" <terri@.cybernets.com>
> wrote:
>
>