Why does UPDATE.WRITE () only work if I use [column] .WRITE () but not [table]. [Column] .WRITE ()?

I execute the UPDATE.WRITE () statement and find out that it only works explicitly if you define it like this:

string sql = "UPDATE [dbo].[Table] SET [Column].WRITE(@data, @offset, @count) WHERE ..."; ... sqlCommand.ExecuteNonQuery(); 

However, if I use [dbo].[Table].[Column].WRITE(...) or [Table].[Column].WRITE(...) , an exception is thrown:

 Incorrect syntax near 'WRITE'. Stack trace: at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection) at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj) at System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj) at System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString) at System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async) at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, DbAsyncResult result) at System.Data.SqlClient.SqlCommand.InternalExecuteNonQuery(DbAsyncResult result, String methodName, Boolean sendToPipe) at System.Data.SqlClient.SqlCommand.ExecuteNonQuery() ... 

Why? This is not like the usual way to build SQL statements. Does it make sense in this seemingly exceptional agreement, where you are clearly not allowed to explicitly specify the table name and schema?

+4
source share
1 answer

This does not seem very consistent ...

In fact, this is consistent with the rest of the SET clause :

 SET { column_name = { expression | DEFAULT | NULL } | { udt_column_name.{ { property_name = expression | field_name = expression } | method_name ( argument [ ,...n ] ) } } | column_name { .WRITE ( expression , @Offset , @Length ) } | @variable = expression | @variable = column = expression | column_name { += | -= | *= | /= | %= | &= | ^= | |= } expression | @variable { += | -= | *= | /= | %= | &= | ^= | |= } expression | @variable = column { += | -= | *= | /= | %= | &= | ^= | |= } expression } [ ,...n ] 

That is, it is never valid in the SET clause to indicate a table or schema on the left side of the task (you can, of course, refer to other tables by name or alias, in expression on the right side). The table to update is already identified between UPDATE and SET .

+6
source

Source: https://habr.com/ru/post/1490224/


All Articles