Grouping shift data by 7-day windows in SQL Server 2012

What I want to do is to calculate the number of shifts and hours worked by each employee in any given 7-day period. In order to achieve this, I need to identify and group ‘islands’ of shifts. Note …

Cast/Convert nvarchar to datetime

i have table: id timestamp 1 31.10.2020 16:32:11 2 09.09.2020 09:15:49 3 22.04.2020 02:48:15 Table have huge amount these data. Column timestamp is data type “nvarchar”. And i …

The multi-part identifier “t7.rate_buy” could not be bound

Please help me on this error message: The multi-part identifier “t7.rate_buy” could not be bound. I can’t find how to fix this. I use SQL Server 2012 and I have tried everything but I can’…

Self Join to calcuate one day before a given date

I have this table Employee_Hire which has Hire date of an employee (ID) in a Department. Now I want to write a Select query which adds one more column (Last_day) to show last day he worked in that …

Stored procedure runs correctly only sometimes

My problem is: I have a stored procedure that only sometimes runs correctly, sometimes it does not run at all and sometimes partially (some rows where inserted in the table bot not all). I use lazarus …

Reading 0.5 value in ROW_NUMBER() and PARTITION BY | SQL Server 2012

I have this question before Looping between 2 case parameters (Date Range and Row Count) | SQL Server 2012 , now I’m thinking about a scenario, what if the value has a 0.5? or .5? Will this work using …

Joining two different tables with a common third table on a common column

Here are the tables Table: Status ID, StatusDesc 1, New 2, Active 3, Cancelled 4, Complete Table: Order (foreign key relationship with Status table above) ID, OrderNumber, StatusID 1, 1001 , …

Converting string to integer and then converting back to string

I have some update statements like this: UPDATE tmp SET MyVarCharColumn1 = ISNULL(SomeOtherVarCharColumn,0) FROM #myTempTable tmp; Note that MyVarCharColumn1 is of type VarChar() but in real …

How to use an IF statement within a view to drop/use a #Temp Table?

I need to create a view, which begins with the following SQL: IF OBJECT_ID(‘tempdb..#TempTable’) Is Not null Drop Table #TempTable I am also rebuilding this #TempTable further on in the view, and …

SQL Return last record where column value changed and amount of change

In MS SQL 2012, I have a table like such: Key | Entity | Value | DateTime ———————————————————– 10 A 800 …