How to delete duplicate values for a field in a table with a single query?

I want to delete from a table the entries where it has multiple values for Date field. So say I have Employee table – Id,Name,Date,Points I want to delete the entries with same Date field which should be unique…just to cleanup I need to just keep a single entry for date and delete the rest…maybe […]

Select matching rows as columns

I think it would be quickest to show by example, so here goes a simplified version of my problem. I am using SQL Server. This is the data model SURVEY QUESTION ANSWER —— ——– ——- surveyId questionId answerId questionText surveyId questionId answerText Here’s some sample data SURVEY QUESTION ———- ———— ————– | surveyId | | […]

SqlDataAdapter does not fill DataSet

I’m using VS2012 and SQL Server Express 2008. I’ve boiled down my connection/query to try and find out why my DataSet is not being filled. The connection is completed successfully, and no exceptions are thrown, but the adapter does not fill the DataSet. The database that this is pulling from is on the same PC […]

does it makes sense to do SP for simple queries like select * from users

is it going to be faster if instead of doing select * from users where id = 1 or delete from users where id = 1 or select count(*) from users I would create a SP for it ?

Group By Different Values

I would like to group by the first day and then the rest of the month, I have data that spans years. I have data like below: ————————————– DAY MONTH YEAR VISITOR_COUNT ————————————– 1 | 12 | 2014 | 16260 2 | 12 | 2014 | 15119 3 | 12 | 2014 | 14464 4 […]

SQL: Running two queries at once and Assigning Variables

I am basically trying to run these two queries: SELECT * FROM ProductTable; SELECT CAST(CASE WHEN COUNT(*) > 0 THEN 1 ELSE 0 END AS BIT) FROM UserTable WHERE id = 41; Both queries work properly. The first one returns me all the data in ProductTable. The second query returns me either 1 or 0 […]

Import data into sql server from files with different format

I have a program, which watches a folder on the server. when new files (flat file) come in, the program (C#) read data, bulk insert into the table. it works fine. Now, we extend the system. It means the data files could be in different formats (flat file, csv, txt, excel..), or with different columns […]

SQL – Operand data type varchar is invalid for sum operator

I’m running the following query and getting the Operand data type varchar is invalid for sum operator error. The accountnature field is a varchar field, but I’m casting it as INT and I’m still getting the error. SELECT ‘Qualified’ =sum(case when (cast(AccountNature AS Int)) in (‘a’,’b’) then ‘1’ end) from agreement group by accountnature Any […]

SQL Stored Proc Executing Select before gettting values from other procs

Got a strange problem created a little stored proc which need to execute a couple of other stored procs to get some values before executing the main select statement see below, set ANSI_NULLS ON set QUOTED_IDENTIFIER ON GO ALTER PROCEDURE [dbo].[usp_get_ApplicationUserServiceRoles] @UserId int, @ApplicationName varchar(50), @ServiceName varchar(50) AS BEGIN —————————————– SET NOCOUNT ON —————————————– DECLARE […]

SQL REPLACE giving error: 'String or binary data would be truncated.'

I’m trying to replace just part of a string in our company database. The column in which I’m trying to update is MERGECODES (varchar(20),null). A typical value of this column would be something like ‘M, GPE, T’. I would like to replace every instance of T with KD but I’m getting the error below. It […]

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