Case statement help for replacing null from multiple joins

so i have the following case below where if jl name does not have n/a i want it to come from the same column. if there is n/a i want to look into this subquery and find the recent jl name. but if the …

How to convert date integer keys into datetime in SQL

after a lot of struggle, I cannot convert datekey (20200430) and timekey (103500) into proper datetime (2020-04-30 10:35:00). I do not have an option of joining on date dimension, the numbers must be …

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 …

How to save SQL query analytics in the background while still delivering records to user?

I am interested in knowing if there is an efficient way to record the analytics from a SQL query while still providing the records to the requester? I’m currently on MS SQL Server 2012. Let’s say for …

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