SQL Server : insert data into temporary table using a variable

I am trying to insert the result in @date into temporary table, here is my co DECLARE @MinDate DATE = CONVERT(VARCHAR(15), DATEADD(month, DATEDIFF(MONTH, 0, GETDATE()), 0), 101), @MaxDate DATE = CONVERT(VARCHAR(15), EOMONTH(GETDATE()), 101), @dayInMonth VARCHAR(15); DECLARE @date DATE; DECLARE @counter INT = 0; DECLARE my_cursor CURSOR LOCAL STATIC READ_ONLY FORWARD_ONLY FOR SELECT TOP (Datediff(day, @MinDate, […]

Can Directory.Move fail because I am browsing the folder?

I have two folder in a remote FileShare and I am trying to move the first one inside the second. To do this, I wrote a CLR that pretty much does the following: if (Directory.Exists(destinationFolder)) { Directory.Delete(destinationFolder, true); } if (Directory.Exists(sourceFolder)) { Directory.Move(sourceFolder, destinationFolder); } This works as expected but there are some cases that […]

sql where clause with multiple conditions c# web service

This question already has an answer here: An issue of SqlCommand with parameters for IN [duplicate] 3 answers

SQL Server syntax for named keys/indices inside table declaration

I am creating a database from scratch, and I want to document the database design in a clear way for review/documentation. Therefore I want to: Name my primary key PK_Foo_Bar inside the table declaration (unlike how I declared my index) Name my foreign key FK_Foo_Baz inside the table declaration Put the named index IX_Foo_Baz inside […]

SQL – How to create a trigger involving 2 separate tables?

Create an INSERT trigger called checkPub on the ‘publishers‘ table to add a row into the ‘pub_info‘ table 1) when a row is inserted into the ‘publishers’ table with the values of the pub_id inserted into the publishers table, 2) NULL in the logo column, and 3) the text ‘Newbie’ in the pr_info column. 4) […]

Count numbers of days worked for Employees in SQL Server

I have a database containing transactional data. I am trying to count the number of days all employees worked between ‘2016-03-01’ and ‘2017-03-01’. What I am using to determine the days worked per employee is by doing a count(distinct day(datecompleted)) where datecompleted resembles a day that an employee completed an activity as the driver. The […]

SELECT all columns from distinct two columns

I need to SELECT * where distinct ‘Rua’ with different ‘CP’ in the following DB: id Rua Local Conc CP 81143 dos moinhos Rio Tinto Gondomar 0123 81142 dos Moinhos Rio Tinto Gondomar 4435 81141 dos Moinhos Rio Tinto Gondomar 4435 With the following query, i am able to obtain the two columns: SELECT Rua, […]

SQL Server 2008, pivot with no aggregate fuction

I have a database table that looks like this: product||installed/removed||date A|| 1||Jan 1, 2016 A|| 0||Mar 16, 2016 A|| 1||May 15, 2016 B|| 1||Feb 3, 2016 C|| 0||Nov 15, 2015 D|| 1||Dec 4, 2015 installed/removed is a flag which means 1 = installed, 0 =removed. I want to make it look like this: Product|| 1|| […]

SQL Server – Add or Subtract from Previous Value

I’m trying to get the balance from this data Date Logged Closed ————– ———– ———– 1-Jan-2016 0 0 2-Jan-2016 8 7 3-Jan-2016 8 8 4-Jan-2016 25 11 5-Jan-2016 20 16 6-Jan-2016 14 13 7-Jan-2016 10 12 8-Jan-2016 9 7 9-Jan-2016 12 12 10-Jan-2016 3 4 The expected output is Date Logged Closed Balance ————– ———– […]

Sonar 5.6.4 and 6.1 fails to install on fresh MS SQL Server 2012

When I start Sonar on fresh (empty) MS SQL Server 2012 DB it runs some migration code which fails. I get error below. I can provide full log if anyone is able to create issue in Sonar JIRA. Could it be problem with locale set on driver side? 2017.01.17 12:32:40 INFO web[DbMigration] == CreateDefaultUsersAndGroups: migrating […]

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