I'm looking at some SQL code which has a WHERE clause like this:
WHERE 'USD' = CCY
I asked the writer why he's putting the value on the left hand side, and he said it's best practice to do so, stemming from C++ where people could mistakenly assign the value instead of comparing equality by forgetting the second equals sign.
I've never seen this before.
What are your thoughts?
The & means "Don't take the variable, take the place in memory where this variable is stored." It's a little complicated, but it's necessary so that C can change the value of the variable.
The plus(+) sign before the variables defines that the variable you are going to use is a number variable.
It passes a reference to the variable so when any variable assigned the reference is edited, the original variable is changed. They are really useful when making functions which update an existing variable.
All variables in PHP start with a $ sign, followed by the name of the variable. A variable name must start with a letter or the underscore character _ . A variable name cannot start with a number. A variable name in PHP can only contain alpha-numeric characters and underscores ( A-z , 0-9 , and _ ).
Er, C++ is not SQL. There's no ==
in SQL and no assignments in a WHERE
clause.
I'm not sure it qualifies as "best practice" but there is a convention which places the known value on the right-hand side. So, with a literal as in your example that would be
WHERE CCY = 'USD'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With