ntangeman
(Nikki)
February 26, 2025, 8:10pm
1
Hello!
What is the formula if I want to take the difference in days between an invoice due date and the date I entered in my parameter?
I would’ve thought it would be:
DateDiff (Day,InvcHead.DueDate, @Date )
But the syntax says “Common table expression defined but not used.”
Thanks!
Not sure how case sensitive that is, I always use
DATEDIFF(day,
1 Like
Randy
(Randy Stulce)
February 26, 2025, 8:23pm
3
1 Like
JMPCONJ
(John Magee)
February 26, 2025, 8:24pm
4
Make sure the parameter’s defined as a date format
Suggest renaming the parameter to be @XDueDate or something like that…wonder if the BAQ’s getting squirrely in translating @Date
EDIT - or ignore me and follow @Randy lol
Randy
(Randy Stulce)
February 26, 2025, 8:26pm
5
@JMPCONJ is correct a query can’t use SQL Reserved Words. I believe that “Date” is one. Good catch John!
dcamlin
(David Camlin)
February 26, 2025, 8:28pm
6
May need to print that on a T-shirt for Insights…
2 Likes
JMPCONJ
(John Magee)
February 26, 2025, 8:29pm
7
So it’s the sequence of the DateDiff command AND the parameter name.
Reminds me of the SNL bit…it’s a floor wax AND a dessert topping
2 Likes
Randy
(Randy Stulce)
February 26, 2025, 8:30pm
8
I think “In Hannah we trust” would make a better t-shirt and be more accurate.
2 Likes
dcamlin
(David Camlin)
February 26, 2025, 8:35pm
9
I think two people standing side-by-side with those shirts would be pretty funny.
“In Hannah we trust… or, ignore me and follow Randy.”
Though, it changes the connotation to make it sound like following Randy is the poor choice, haha.
Kinda like:
“You shouldn’t step out into traffic… but, hey, do what you want.”
1 Like
Randy
(Randy Stulce)
February 26, 2025, 8:37pm
10
That’d probably be the safer assumption.
ntangeman
(Nikki)
February 26, 2025, 8:38pm
11
Okay - it appears this is the correct way and I just had a different error. Thanks all!
2 Likes
jtownsend
(John Townsend)
February 26, 2025, 8:40pm
12
Technically, @Date isn’t the same as Date, the latter is (as you stated) reserved and will cause issues unless enclosed in brackets (in SQL). BAQ’s will usually handle that, but it’s a bad practice. You can go wild on @Variable names.
1 Like
JMPCONJ
(John Magee)
February 26, 2025, 8:49pm
13
I usually just stick parm* in front of whatever field I’m querying against:
parmOrderNo, parmCustID, parmPartNum
-* only because a prefix of “chickenparm” or “vealparm” or “meatballparm” as the prefix seems a little too verbose
1 Like
Randy
(Randy Stulce)
February 26, 2025, 8:54pm
14
JMPCONJ:
chickenparm
Hmm, I read that as Chicken Parmesan
jtownsend
(John Townsend)
February 26, 2025, 8:56pm
15
I withhold judgement on @ChickenParm until I review the T-SQL naming conventions again.
Hally
(Simon Hall)
February 27, 2025, 2:35pm
17
But the real question is it Chicken Parma or Chicken Parmi… or Chicken Parmy?
As long as it good quality ham and lots of cheese, and followed closely with a good cold beer. That’s all that should matter.
Talking of dateadd. I learnt today trying to put DateTime.Today.AddDays(-2) into a linq statement in a function does not work, compiles but errors on execution.
2 Likes
jwphillips
(Jonathan Phillips)
February 27, 2025, 2:52pm
18
There must be some other issue. That’s a valid C# expression.
Only think I can think is that there are limitations in LINQ to SQL (IQueryable) statements.
1 Like
Hally
(Simon Hall)
February 27, 2025, 3:07pm
19
when I looked it up I ended up having to create the variable i.e.
var TwoDaysHence = DateTime.Today.AddDays(-2);
and then put TwoDaysHence into the linq statement.
worked after that…
1 Like