Updating records in SQL Server 2005 with ASP.NET 3.5 – HOW TO?

I have ALWAYS used the SQLDataSource to update my records in my SQL Server 2005 database, so i am not really sure how this would be done in normal code. I am using VB.NET but if you are a C# developer and want to show me some code that is more than welcome as well. […]

How can I find out which rows (if any) have a non-unique value in a column?

I have the following table in my SQL Server 2012 database: CREATE TABLE [dbo].[Problem]( [ProblemId] [int] IDENTITY(1,1) NOT NULL, [SubTopicId] [int] NOT NULL, [ReferenceId] [int] NOT NULL, [ProblemStatusId] [int] NOT NULL, [Locator] [nvarchar](50) NULL ) The Locator is supposed to be unique but I think there are some cases where more than one row has […]

Select top n order by fleld1, then re-order by field2

I need to select the most recent 100 records by order number (returning a total of 100 records): select top 100 orderNo, orderDate, orderTypeName, field1, field2, name, address from orders where dispatched = 1 order by orderNo desc (orderNo is sequential and the highest number is the latest order). This gets me the most recent […]

SQL to identify out of tolerance values

I have a database table with the following structure – Week_End Sales 2009-11-01 43223.43 2009-11-08 4324.23 2009-11-15 64343.23 … What I want is a SQL statement that will take a start and end date, and identify all rows within that period where the sales figure is more than 3% above or below the average sales […]

SQL different aggregates in single query

I am trying to work out a query where I have a table representing the following: and I need the result to indicate the earliest start time (blue), the latest end time (green), and the sum of the lunch breaks (yellow): I got the blue and green blocks right, but are struggling with the yellow […]


Is it possible to do something like this with IF-ELSE, or something similar: SELECT MemberID, ProfileTypeID PrCountryID, — 3 PrStateID, — 4 PrStateInt FROM Member WHERE PrCity IS NOT NULL IF @ShowUnclaimed = ‘N’ AND Claimed = ‘Y’ AND SBIcon = ‘N’ END AND Viewable = ‘Y’ AND SystemID = 2 Many thanks in advance […]

Use WHERE clause when execute stored procedure

I’ve stored procedure to view data transaction by joining other tabel create procedure prRecapitulation as begin SELECT a.TransactionID, a.Buyer_Code, a.Date_Transaction, b.NuggetID, SUM(b.Qty) as Qty, SUM(b.Sub_Total) as Sub_Total, SUM(a.Total_Price) as Total_Price FROM Transactions a JOIN DetailTransaction b On a.TransactionID = b.TransactionID WHERE DAY(a.Date_Transaction) = 21 AND MONTH(a.Date_Transaction) = 01 AND YEAR(a.Date_Transaction) = 2017 GROUP BY a.TransactionID, […]

SQL Query MAX(count(*))

I need to get IdPasajero and the maximum number of tickets purchased from the list of a Boletos table that has the record of all tickets purchased by IdPasajero. any ideas? My Thoughts: SELECT MAX(contador) FROM ( SELECT IdPasajero, count(idPasajero) contador FROM Boleto GROUP BY IdPasajero ) T; This returns only the maximum amount purchased […]

SQL Where clause pass list to a column

I have some table DOCUMENTS that have a column TYPE_ID and a table named TYPES Now I want to make a query which filter on my DOCUMENTS all the document that have a list of TYPE_ID that can be a single element or sort of elements The normal query is: Select * From DOCUMENTS Where […]

C# SQL connection

I want to create simple application with GUI, where i can input SQL Server name and id that must be updated with this string: update docs SET locked=0 WHERE ID=(id entered in GUI) Any suggestion?

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