I wrote a simple insert into statement: I got this error: Cannot insert the value NULL into column ‘Worker_ID’, table ‘Worker’; column does not allow nulls. INSERT fails (By the way Worker.WorkingPlace is a nullable column) I’m very confused, because I’m just inserting data into the ‘WorkingPlace’ column, aren’t I? Answer This will create as many new rows in table
Tag: sql-server
Increment column value based on condition
I’d like to increment the values in the column nc by 1 each time the value in 10minDiff changes. In the Table below, the values in nc should read 2 from row 1246 onwards and 3 the next time 10minDiff changes from 10. Answer Since data is not textual.I am writing UnTested query.
Trigger causing Maximum trigger nesting level exceeded
I have created a new trigger that updates my [Purchase Table] if the number of delivered items equals the ordered quantity, but every time it’s run I get the following error. ODBC–update on a linked table ‘dbo_Purchase Table’ failed. Maximum stored procedure, function, trigger or view nesting level exceeded (limit 32). (#217) This is the trigger that I have created:
Return Date Ranges based based on a given interval between two given dates in SQL
I am trying to get a list of all DateRanges of a given interval between two dates. For example if I have the dates 2015-04-01 and 2015-06-20 and when the interval is 20 the result should be Here is the query I am trying Its returning the below result which is not exactly as my expected result above Here as
SQL pivot and group by month
I’m trying to get the sum of production per month and pivot the month row to columns. Could you please tell me what is wrong with this code?’ Answer There were several items wrong in your query. Columns need aliases and your max() within the PIVOT was referencing an invalid column name
Simplifying SELECT statement
so I have a statement I believe should work… However it feels pretty suboptimal and I can’t for the life of me figure out how to optimise it. I have the following tables: Transactions [Id] is PRIMARY KEY IDENTITY [Hash] has a UNIQUE constraint [BlockNumber] has an Index Transfers [Id] is PRIMARY KEY IDENTITY [TransactionId] is a Foreign Key referencing
Returning non-overlapping records within a date range
I have the following data. I have looked over a lot of threads about overlapping and non-overlapping dates but none seemed to help me. From this table with a SQL query I want to return the first record out of overlapping dates or basically I have been struggling a lot with this query and was wondering if this is actually
Java to SQL Server using Windows Authentication
I am trying to connect to a remote SQL Server DB from a Java application without success. I am able to successfully connect to that SQL Server instance from a SQL client for Mac called SQLPro for MSSQL However, if I try to connect from the Java application using those same credentials, I always get a Login failed error, this
Select id of user for specific email, or max(id)+1 if email doesn’t exist
I want to get the id of a user for a given email, or if the email doesn’t exist, I want it to return MAX(id)+1. So for the example below, I want: For email ‘aaa@gmail.com’, I want it to return 1 For email ‘kkk@gmail.com’, I want it to return 9 I made an attempt but I couldn’t make it work
Problem with creating a SQL view with multiple joins
I am trying to create a view which will be a base for Excel export in API. Basically, what it contains is information about particular projects. To said projects calculations can be added (it all happens on the form on frontend). Those calculations are called EBIT, EBIT+ and OVI. User can add either one, two or all of them, so