March 15, 2016 at 12:23 am
I have this query
DECLARE @TheDate DATE
IF @TheDate IS NULL
SET @TheDate = GETDATE()
SET @FileName = 'DailyAgentSales' + CONVERT(CHAR(8) ,@TheDate -1 ,112) + '.csv'
SET @Subject = 'Agent Sales - ' + CONVERT(CHAR(8) ,@TheDate -1 ,112)
And I'm getting this error: Operand type clash: date is incompatible with int,
what it this error and where do I start to look at to solve it?
March 15, 2016 at 12:58 am
hoseam (3/15/2016)
I have this queryDECLARE @TheDate DATE
IF @TheDate IS NULL
SET @TheDate = GETDATE()
SET @FileName = 'DailyAgentSales' + CONVERT(CHAR(8) ,@TheDate -1 ,112) + '.csv'
SET @Subject = 'Agent Sales - ' + CONVERT(CHAR(8) ,@TheDate -1 ,112)
And I'm getting this error: Operand type clash: date is incompatible with int,
what it this error and where do I start to look at to solve it?
March 15, 2016 at 2:46 am
It's coming from this fragment: @TheDate -1
You can't add or subtract integers from a DATE variable. Try DATEADD(dd,-1,@TheDate) in both places where that occurs
Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability
March 15, 2016 at 7:48 am
Thank you
March 15, 2016 at 11:23 pm
You could also change this...
DECLARE @TheDate DATE
... to this ...
DECLARE @TheDate DATETIME
... and continue to do the -1 trick.
Heh... now duck... here come the DATE/TIME police whose hair just burst into flames. 😛
--Jeff Moden
Change is inevitable... Change for the better is not.
March 16, 2016 at 12:26 am
Eirikur Eiriksson (3/15/2016)
hoseam (3/15/2016)
I have this queryDECLARE @TheDate DATE
IF @TheDate IS NULL
SET @TheDate = GETDATE()
SET @FileName = 'DailyAgentSales' + CONVERT(CHAR(8) ,@TheDate -1 ,112) + '.csv'
SET @Subject = 'Agent Sales - ' + CONVERT(CHAR(8) ,@TheDate -1 ,112)
And I'm getting this error: Operand type clash: date is incompatible with int,
what it this error and where do I start to look at to solve it?
He he, tried to post the answer from a moving London Underground train, just noticed now that the actual answer never made it to the surface:-P
😎
Viewing 6 posts - 1 through 5 (of 5 total)
You must be logged in to reply to this topic. Login to reply