|
I'm struggling to see how that would be possible.
- A view cannot insert, update, or delete any records. It can only select records.
- A view can select from a table-valued function, but a TVF cannot insert, update, or delete records. Neither can it call a stored procedure, or use temporary tables.
- You can't create a trigger that would fire when records are selected from a table or view. And you can't create triggers on TVFs at all.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Richard Deeming wrote: A view cannot insert, update, or delete any records. It can only select records.
Actually it can under some circumstances
MSDN wrote: You can modify the data of an underlying base table through a view, as long as the following conditions are true:
Any modifications, including UPDATE, INSERT, and DELETE statements, must reference columns from only one base table.
The columns being modified in the view must directly reference the underlying data in the table columns. The columns cannot be derived in any other way, such as through the following:
An aggregate function: AVG, COUNT, SUM, MIN, MAX, GROUPING, STDEV, STDEVP, VAR, and VARP.
A computation. The column cannot be computed from an expression that uses other columns. Columns that are formed by using the set operators UNION, UNION ALL, CROSSJOIN, EXCEPT, and INTERSECT amount to a computation and are also not updatable.
The columns being modified are not affected by GROUP BY, HAVING, or DISTINCT clauses.
TOP is not used anywhere in the select_statement of the view together with the WITH CHECK OPTION clause.
CREATE VIEW (Transact-SQL) - MSDN[^]
<edit>BTW, most databases support it since it's standardized in SQL-92</edit>
|
|
|
|
|
But that's only if you issue an INSERT , UPDATE or DELETE statement against the view.
My interpretation of PIEBALDconsult's message is that he's only reading the view - a SELECT statement. And I can't think of any way that a SELECT statement against a view could modify the underlying data.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
I got the impression he's "reading" the view via an SP or similar.
Piebald wrote: in this case I'm "just reading" from the view, but apparently something (a function or who knows what) is making changes.
Anyway, that means I misread what you wrote.
|
|
|
|
|
An ETL in SSIS actually, but that's just details, if I say SELECT ... FROM someview that should cause the data to change.
|
|
|
|
|
Then the only possibility I can think of is if some idiot (IMHO) has created a trigger on the view.
|
|
|
|
|
SQL Server doesn't let you create a trigger that fires on a SELECT .
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Quite right you are.
I need to get rid of this cold. My brain is getting mushy.
|
|
|
|
|
Exactly. That's been covered.
|
|
|
|
|
Yeah, I don't know either.
If they're not smart enough to know not to do it, then they're probably not smart enough to know how to do it.
I can imagine a CLR function that could pull data from somewhere, but that's just not a good idea.
For example SELECT id , name , GetManagerID(id) FROM usertable
And in the background, the GetManagerID function accesses LDAP and refills the usertable or something.
|
|
|
|
|
ISomething something = listOfSomethings.Where(...).OrderBy(...).FirstOrDefault();
if (something != null)
{
return something;
}
else
{
return null;
} Oh no, how come you thought you could return something when it is null ? That's a different null !
|
|
|
|
|
Saw similar in javascript last week:
function checkIfValid() {
var isValid = false;
if (doSomeOtherCheck()) {
isValid = true;
}
...
if (isValid == true) {
return true;
} else {
return false;
}
}
[Edit] Updated to show more content from the function.
Ah, I see you have the machine that goes ping. This is my favorite. You see we lease it back from the company we sold it to and that way it comes under the monthly current budget and not the capital account.
modified 31-Aug-21 21:01pm.
|
|
|
|
|
That makes sense if valid is "true" (string) or 1 (int), but you want to return a boolean
|
|
|
|
|
I should have wrote that further up the function, isValid is set to either true or false
Ah, I see you have the machine that goes ping. This is my favorite. You see we lease it back from the company we sold it to and that way it comes under the monthly current budget and not the capital account.
modified 31-Aug-21 21:01pm.
|
|
|
|
|
|
Using the "null" keyword in code should produce a compilation error. Not that it would break enything, right?
|
|
|
|
|
Maybe it is work in progress and the something should get some calls in the future...
Press F1 for help or google it.
Greetings from Germany
|
|
|
|
|
Actually they are different things, kind of. The FirstOrDefault is going to return
default(ISomething)
Your assertion that "something" is going to be null is actually an assumption. The code would indeed be redundant if it was this
ISomething something = listOfSomethings.Where(...).OrderBy(...).FirstOrDefault();
if (something != null)
{
return something;
}
else
{
return default(ISomething);
}
however we're getting into new levels of pedantry here I sometimes write things like in the OP if I want to make it explicitly clear that it is expected that the function can return a null value.
|
|
|
|
|
F-ES Sitecore wrote: The FirstOrDefault is going to return default(ISomething)
Not necessarily. Assuming ISomething is an interface, default(ISomething) will be null . But:
interface ISomething { }
struct Something : ISomething { }
var listOfSomethings = new List<Something>();
ISomething result = listOfSomethings.FirstOrDefault();
Console.WriteLine(result == null);
For an empty sequence, FirstOrDefault returns default(TSource) , where TSource is the type parameter of the input sequence.
And if ISomething isn't an interface, then whoever wrote the code needs to be introduced to the clue-bat.
Now that's a new level of pedantry!
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
A-H are my replacements of more descriptive types to anonymize this drech slightly. I left the misspelling in.
public string getTransactionType(string TransactionType)
{
if (TransactionType == ("A"))
{
TransactionType = "1";
}
else if (TransactionType == ("B") || TransactionType == ("C"))
{
TransactionType = "3";
}
else if (TransactionType == ("D") || TransactionType == ("E") || TransactionType == ("F"))
{
TransactionType = "4";
}
else if (TransactionType == ("G"))
{
TransactionType = "5";
}
else if (TransactionType == ("H"))
{
TransactionType = "6";
}
return TransactionType;
}
Now granted, the point is to return a code given a type. But the method is misnamed, the way it's done is horrid, and what's worse, the now encoded type is used everywhere else in the code for conditional logic so you have no idea what the logic is doing without this piece of the type-code map.
And putting strings in parenthesis definitely improves the confidence of the equality test!
Marc
|
|
|
|
|
What happened to 2
|
|
|
|
|
Wastedtalent wrote: What happened to 2
That was yesterday - see previous post. I just didn't put "day 2" in the subject line.
Marc
|
|
|
|
|
|
The first rule of Transaction Type 2 Club is: ...
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
Wastedtalent wrote: I meant transaction type
Oops. Don't know. I'll have to see if it's every used in the code!
Marc
|
|
|
|