Issues with 1) submitting a question on SQL Server and 2) Preview display issue in the asking question form

Sviatlana Hodzina 21 Reputation points
2022-09-17T12:41:29.467+00:00

1) There is an issue with submitting a question on SQL Server issue.
2) The preview is not displayed in the question submitting form.

The question for submitting: I'm a newcomer in learning SQL Server. The question is: what might be the reason for the following issue? :

Updating a table with setting xml datatype into the column the result says, that 'the query executed successfully'. But the actual result displays NULL. Here is the SQL query for updating the table:

DECLARE @xmlData xml
SET @xmlData = '<AdditionalContactInfo>
<value1>Input data</value1>
<value2>Input data</value2>
<value3>Input data</value3>
<value4>Input data</value4>
</AdditionalContactInfo>'
UPDATE Person.Person
SET @xmlData = AdditionalContactInfo,
ModifiedDate = GETDATE()
WHERE BusinessEntityID = 10780

SQL Server
SQL Server
A family of Microsoft relational database management and analysis systems for e-commerce, line-of-business, and data warehousing solutions.
13,670 questions
{count} votes

Accepted answer
  1. Erland Sommarskog 110.3K Reputation points
    2022-09-17T12:56:17.323+00:00

    1) There is an issue with submitting a question on SQL Server issue.

    And that issue is?

    2) The preview is not displayed in the question submitting form.

    Yes, I have noticed this as well. It seems to happen when I have a larger piece of code that I have enclosed in backticks to get formatting for source code. I have never bothered to report this. But you can click on Feedback in the top bar to find a place to report the issue.

    As for your question, I am not sure that I understand it. You say that you get NULL back, but it is only an UPDATE query, so result at all is expected. Where are you seeing NULL?

    0 comments No comments

5 additional answers

Sort by: Most helpful
  1. Sviatlana Hodzina 21 Reputation points
    2022-09-17T13:56:10.363+00:00

    Mr. ErlandSommarskog,

    About preview issue: yes, I reported it as feedback before.

    Yes, it is UPDATE query with insert the xml data type into an appropriate field of the existing row. And as it is supposed, the result should be either the query's performance with error, or in case of successful action there should be displayed my inserted data. The NULL is displayed on my GET query for the updated row in the table. - "As for your question, I am not sure that I understand it. You say that you get NULL back, but it is only an UPDATE query, so result at all is expected. Where are you seeing NULL"

    0 comments No comments

  2. Erland Sommarskog 110.3K Reputation points
    2022-09-17T15:17:33.113+00:00

    Not sure why you accepted my Answer as answer, when it clearly did not answer your question.

    Viorel makes a good point. You have

       UPDATE Person.Person  
       SET @xmlData = AdditionalContactInfo,  
       ModifiedDate = GETDATE()  
       WHERE BusinessEntityID = 10780  
    

    This means "Set the column ModifiedDate to the current date and time, and save the value of the column AdditionalContactInfo in the variable @xmlData.

    We as humans might guess that what you really wanted to do is to save the value of @xmlData into AdditionalContactInfo. But computers are stupid. They just do what they tell them do. If the are not able to understand the instructions, for instance because the syntax is not correct, they will react with an error. But this case, you had perfectly legal T-SQL, so therefore you did not get any error message.

    So that is the lesson to learn: just because you don't get an error message, does not that everything completed successfully from your point of view. The result may still be incorrect. But the computer is not intelligent enough to understand that.

    What you supposedly had in mind is:

       UPDATE Person.Person  
       SET AdditionalContactInfo = @xmlData,  
       ModifiedDate = GETDATE()  
       WHERE BusinessEntityID = 10780  
    
    0 comments No comments

  3. Sviatlana Hodzina 21 Reputation points
    2022-09-17T16:25:18.047+00:00

    I accepted your answer as a fact that you did answer me even though you see my request's solution in your way, and I do accept it. - "Not sure why you accepted my Answer as answer, when it clearly did not answer your question."

    As I am just in a learning process, I don't claim or insist on my answer to be final right. I only suppose that if you write your query in the wrong way or with the wrong syntax, the result of the query shouldn't be 'Successful'. It may misguide the user whether he/she is a learner or an expert accidentally input the data in a wrong way. In case your data is not inserted due to any reason, the message shouldn't display 'successful'. Programs, data bases are written by people. - "So that is the lesson to learn: just because you don't get an error message, does not that everything completed successfully from your point of view. The result may still be incorrect. But the computer is not intelligent enough to understand that."


  4. Erland Sommarskog 110.3K Reputation points
    2022-09-18T15:46:35.017+00:00

    What is the reason for that fact of not displaying the real result of the query made, (successful or failed) if a user makes a wrong syntax or whatever (that I don't really consider to be right)?

    Let's try this again:

    1. You gave the computer instructions to perform an operation.
    2. The computer said to itself "Can I make sense of these instructions?".
    3. The answer was yes, and the computer carried out the instructions.
    4. And since the operation completed without errors, the computer reported a successful outcome.

    From your point of view it did not, because you intended something else. However, the computer is way too dumb to be able read between the lines. It does exactly what you tell it.

    It is the same as, for a comparison, when you send a message to someone, and in response you get the confirmation: "The message is sent", but actually the receiver doesn't get any messages from you.

    You give me a letter to deliver to a person, but you have somehow confused the address. As it happens, on that address there lives a person with the same name, I deliver the letter to that person, and I come back to you, happily confirming that I have delivered the letter. Could you blame me for a false confirmation? Well, since I'm a human, you could argue that I should understand that you would never send a letter to such a shady part of town.

    However, the computer is entirely without such prejudice. It does not think "Ah, here we have a novice user, who would never intend to perform an advanced operation like this". No, what is legal syntax, is legal syntax for everyone.

    And this is the lesson for you as a learner: if you submit something the computer cannot understand, you will get an error. Likewise, you will get an error, if the computer fails half-way through the operation. But if the computer can understand the instruction and perform it without mishaps, there will be no error message. It is up to you to verify that the outcome was the one you intended.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.