score:7
you have this line in your trigger:
set @mileage = (select mileage from workersettings where worker_id = @workerid)
so if @workerid
is null
or doesn't exist, then @mileage
is going to end up being null
even if you've passed in a proper value for it. this is why the insert
works without the trigger.
score:1
check that milage in workersettings for the workerid associated with the expenseid being inserted is not null.
score:2
let me tell you how to best develop and debug triggers.
first create temptables for #inserted and/or #deleted'
then insert mulitple records into the temp tables that would be the data that the trigger inserted and deleted would have. make sure you cover all the test cases you need. it is critical that you have mulitple records.
then write your code using #inserted instead of inserted.
now you can run in steps and check data before the final action. you can also put the whole thing ina transaction that you can automatically rollback until you get the code right.
finally, i said this in a comment, but never write a trigger assuming only one record at a time will be processed.
once it's right, change the temp table names to inserted or deleted and add the create trigger code.
Source: stackoverflow.com
Related Query
- SQL Trigger is trying to insert a null value but my C# code is passing int 300?
- SQL query shows good database values, but LINQ to Entity framework brings a null value from nowhere
- getting "cannot assign null value to int type" error on linq to sql left join
- My Linq to Sql Insert code seems to work fine but I don't get a record in the database
- Mimicking SQL Insert Trigger with LINQ-to-SQL
- The given value of type String from the data source cannot be converted to type int of the specified target column
- Foreign Key Reference Already Has Value Exception Linq to SQL When Assigning Null
- Searching by fragments if values are string type but search by and entire if value is int
- linq sql find duplicates but take null and empty string as the same
- Linq Sql Int null equal to null. Not returning rows
- The null value cannot be assigned to a member with type Int32 but strings work
- Fastest way to insert a value in int List and then sort the list
- Cannot insert the value NULL into column 'ProductId', table 'ProductDB.dbo.Brand';
- I'm trying to convert a SQL query to linq, but I'm getting stuck on combining group by and max()
- LINQ to SQL sum null value
- Linq help - Sql trace returns result, but datacontext returning null
- Linq Master Detail with Master Primary Key generated with instead of Insert trigger on SQL Server
- Passing a null value as a string
- insert null value into Database when textbox is empty
- Cannot insert the value NULL into column 'ID'
- Get SQL INSERT OUTPUT value in c#
- I'm trying to translate this sql query on Linq to sql query, but i have some difficult on Avg() and DateDiff()
- value cannot be null in Entity Sql Statement
- LINQ to Sql group and sum in subquery but account for null values
- LINQ function to return list but compiler says function doesn't return a value on all code path
- Cannot insert the value NULL into column ... Exception issues
- Return value of stored procedure is correct but column values are all NULL
- LINQ to SQL simple query to get single int value
- How to handle null in LINQ query for nullable int if value not found
- Lambda expression like Sql where value or null
More Query from same tag
- Traverse up a list using Linq
- Allow duplicate keys with ToDictionary() from LINQ query
- Querying data using LINQ in C#
- MongoDB .NET Driver Group By Time Range
- How to make short lambda of multi join?
- Why does .Where() with a Func parameter executes the query?
- How to speed up Linq based data fetching & Looping into different tables?
- Selecting 3 identical items from list
- LINQ query with array element in Where clause
- EF Query with conditional include that uses Joins
- Sorting, rounding and removing duplicates in a list of time stamps using LINQ
- Find in List<t> and return boolean if found
- ASP.NET EF6 Query Model
- Entity Framework Core 3.1 - Linq - Could not be translated. Either rewrite the query in a form that can be translated
- How can I call a method from within a LINQ expression?
- Put items in List with Linq query
- .where on a LazyList not working
- How can I take the information I received with linq and use that information in an if else statement?
- Unwanted request generated with LINQ to Entities
- C# Cast list using Linq using Where function
- LINQ SelectMany and Where extension method ignoring nulls
- IQueryable losing the ORDER BY
- Expanding an IDictionary<Key, IEnumerable<Value>>
- c# Connecting to database using MySQL
- Are LINQ expressions an acceptable way to manipulate data in F#?
- How to add object to list item in c#
- Linq to get a combined list out of lists C#
- AsParallel() executing sequentially
- Flatten LINQ Collection
- Linq Filter Posts by list of Tags