CASE WHEN THEN in hours ELSE in days

I’m working in a failed indicator in SQL Server. if the planned_receive_date is before 12h00pm, the receive_date has to be on the same day. if the planned_receive_date is after 12h00, the receive_date can be until next day. i’ve got this far. i need the hours to decide if its before or after 12.00. but in […]

SQL Server 2014 Cluster Failover Instance, how to reconnect on failover?

I’ve setup an Windows Server Failover Cluster in a test environmnet, and installed a clustered SQL Server 2014 instance on it. The cluster has two nodes, and the network name is SQLINSTANCE. Now from small console application i have a simple loop (which runs fine) that queries a test database every 100ms: while (true) { […]

SQL query to split records by intervals

Let’s assume I have a table which has columns From and To which are dates and a bit type column which identifies whether it is a cancel (1 = cancel). Also an Id which is a PK and CancelId which references what is cancelled. Let’s say I have records which look like: Id From To […]

SQL – cleaner way to select result based on max date?

I have a query that joins to several tables. Based on the column value of one table, I would like the key value of another table. But, when this key value is joined to another table (with the purpose of identifying different date values for that key), several dates appear. I would like to return […]

SQL Server Spatial Indexes Setup

I currently have two tables cities and listings, both have a field called Position and that is a spatial field. My question is have i set up my indexes correctly or should I add/remove some? For cities I do not show them on a map, I only use one query that is relevant to cities […]

Failed to connect to database server. How do I connect to a database that is not on my localhost using powershell and integrated security?

Background to my question At any moment I am expecting the security people in black suits and black sun glasses to come and take me away because of all my sql server login attempts… I used and adapted iris classon’s example to connect to a database via Powershell. The adapted code uses Integrated Security=True” $dataSource […]

Trigger SQL insert and update

I have two table INVENTORY and INPUT create table INPUT( PRODUCTID nvarchar(10), QUANTUMINPUT int ) create table INVENTORY( PRODUCTID nvarchar(10), QUANTUM int, QUANTUMINPUT int, LASTQUANTUM int ) How to create SQL trigger on SQL when insert column QUANTUMINPUT, table INVENTORY change over?

Group continuous date ranges from same table SQL Server

I have following data: CREATE TABLE #Rate ( RateId Bigint ,PropertyId Bigint ,StartDate DATETIME ,EndDate DATETIME ) INSERT INTO #Rate VALUES (100,1000,’2015-01-01′,’2010-01-11′) INSERT INTO #Rate VALUES (100,1000,’2015-01-12′,’2015-02-02′) INSERT INTO #Rate VALUES (100,1000,’2015-02-11′,’2015-02-25′) INSERT INTO #Rate VALUES (100,1002,’2015-01-01′,’2010-01-11′) INSERT INTO #Rate VALUES (100,1002,’2015-01-12′,’2015-02-02′) INSERT INTO #Rate VALUES (101,1000,’2015-02-11′,’2015-02-25′) INSERT INTO #Rate VALUES (101,1000,’2015-01-01′,’2010-01-11′) INSERT INTO #Rate […]

Bookmark look up confusion

New versions of SQL Management Studio render a bookmark lookup as in the picture below. That makes me think the operation is independent from Index Seek (and can run in parallel?). Shouldn’t Index Seek finish first? Its output (physical row IDs) is the input for Key Lookup, right?

Model in django to store working hours of an employee for specific year, month and week

I am creating a Django application for online attendance system that has to store weekly working hours of employees for few years(5 or 6) I want to create a table, that has employeeid, year, month, week and hours(example 4hrs for week1 in Jan 2015 for employee with id 200) I tried creating models(year, month, week, […]

MS SQL Server is a Microsoft SQL Database product, include sql server standard, sql server management studio, sql server express and so on.