Skip to content

Tag: sql-server

SQL ‘insert into select’ into existing table

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…

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.

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 K…

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…

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 fa…