Avatar of zachvaldez
zachvaldezFlag for United States of America

asked on 

stored proc formula returning null

This variable is returning null and it should be yesterday date
Declare @startDate date = Isnull(@startingdate, Dateadd(day, -1, cast(Getdate() as date)))
Microsoft SQL Server

Avatar of undefined
Last Comment
Scott Pletcher
Avatar of Éric Moreau
Éric Moreau
Flag of Canada image

it is returning yesterday's date.

is it possible that you mixed @startDate and @startingDate?
User generated image
Avatar of zachvaldez
zachvaldez
Flag of United States of America image

ASKER

I think so because after the DECLARE,
I did
Begin
   Set @startdate=@startingdate
    Set @enddate=@startingdate
End

that maybe the problem
Avatar of Éric Moreau
Éric Moreau
Flag of Canada image

without knowing where are these lines, it is just impossible for me to say if it is the issue or not!
This variable is returning null  Declare @startDate date = Isnull(@startingdate, Dateadd(day, -1, cast(Getdate() as date)))

No, it isn't.  It's not possible for that expression to return NULL.  Something else must be happening to cause this problem.


Tested on my instance:
DECLARE @startingdate Date = NULL;
Declare @startDate date = Isnull(@startingdate, Dateadd(day, -1, cast(Getdate() as date)))
PRINT @startDate
2021-05-21

GetDate gave: 2021-05-22 13:14:34.717

Microsoft SQL Server 2017 (RTM-CU23) (KB5000685) - 14.0.3381.3 (X64)   Feb  9 2021 12:08:50   Copyright (C) 2017 Microsoft Corporation  Developer Edition (64-bit) on Windows 10 Home 10.0 <X64> (Build 19042: ) (Hypervisor)

The same on:
Microsoft SQL Server 2019 (RTM-GDR) (KB4583458) - 15.0.2080.9 (X64)   Nov  6 2020 16:50:01   Copyright (C) 2019 Microsoft Corporation  Developer Edition (64-bit) on Windows 10 Home 10.0 <X64> (Build 19042: ) (Hypervisor)


ASKER CERTIFIED SOLUTION
Avatar of ste5an
ste5an
Flag of Germany image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of zachvaldez
zachvaldez
Flag of United States of America image

ASKER

I think my mistake was I set the variables twice
Avatar of zachvaldez
zachvaldez
Flag of United States of America image

ASKER

thanks to all
[Withdrawn]
Microsoft SQL Server
Microsoft SQL Server

Microsoft SQL Server is a suite of relational database management system (RDBMS) products providing multi-user database access functionality.SQL Server is available in multiple versions, typically identified by release year, and versions are subdivided into editions to distinguish between product functionality. Component services include integration (SSIS), reporting (SSRS), analysis (SSAS), data quality, master data, T-SQL and performance tuning.

171K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo