1 of x updates failed vs row not found or changed

I’m getting an inconsistent error in a program using linq on submitchanges that says “1 of x updates failed”. I’ve done some research on this and most of what I’ve found suggests that this is caused by data being used by the open data context being changed from elsewhere while the data is in memory. […]

Editing a large dataset for SQLBulkCopy into a SQL Server database

I have a VERY large (50 million+ records) dataset that I am importing from an old Interbase database into a new SQL Server database. My current approach is: acquire csv files from the Interbase database (done, used a program called “FBExport” I found somewhere online) The schema of the old database doesn’t match the new […]

Constraint with Sql statement

I have 2 tables 1.Sales_Items 2.Stock_Items I want to make sure that when any item is inserted in sale_items table then it’s qty must be less than (Stock_Items.qty-Sales_Items.Qty),if this condition is not true then insertion should fail and throw an exception. How should i do this?Do I need to use sql constraint with expression or […]

Sum of TOP 5 PERCENT and sum of all as two columns

I have a table named All_Sources with the following columns: svcmonth source member cost I’m trying to write a query that will return the sum of the costs of the TOP 5 PERCENT of members as the first column, and the sum of the costs of all members in the table as the second column. […]

Parsing through a column to flip names using patindex

So I have a database of customers. I run SELECT * FROM MyTable it gives me back several columns, one of which is the name. Looks like this: “Doe, John” “Jones, Bill” “Smith, Mike” “Johnson, Bob” “Harry Smith” “Black, Linda” “White, Laura” etc. Some are last name, first name. Others are first name last name. […]

How to write same value into 2 Databases?

I need to insert the same values into 2 different databases. What is the best approach in order to do this ? Can I somehow make this using some configurations tweaks, or creating code for each operation is the only way? I’m mainly using Java + MSSQL.

Sql server : xml truncated while querying in php

While querying a xml data from SQL server database, it returns a truncated xml. $db = DB::get(); $db->exec(‘SET ANSI_NULLS ON’); $db->exec(‘SET ANSI_PADDING ON’); $db->exec(‘SET ANSI_WARNINGS ON’); $db->exec(‘SET ARITHABORT ON’); $db->exec(‘SET CONCAT_NULL_YIELDS_NULL ON’); $db->exec(‘SET NUMERIC_ROUNDABORT OFF’); $db->exec(‘SET QUOTED_IDENTIFIER ON’); $query = “select CAST(db.function(199) AS nvarchar(max))”; $result = $db->query($query); $xml = $result->fetchColumn(); If the length of $xml […]

SQL : Get range date from multiple begin and end date

How to get the “max” range of dates from multiple dateBegin and dateEnd ? My question is not well explained (cause im not english) but the example below will show you what I expect. My database : The output I’d like : id_master beginDate endDate 13 26/07/2014 30/08/2014 280 28/09/2013 01/10/2013 280 01/04/2014 11/04/2014 Explain […]

How can I fill a DataTable using a SqlDataReader as fast as when using SqlDataAdapter?

I have wrote a method which return a DataRow as soon as it has been fetched from a IDataReader source (using yield keyword). It works, but it is really slower than filling the DataTable using a SqlDataAdapter. public static IEnumerable<DataRow> AsEnumerable(this IDataReader source) { //create columns DataTable dt = new DataTable(); for (int i = […]

How to retrieve SQL Server Check Constraint Dependency Columns

If I create the following table create table test( id1 int, id2 int, id3 int constraint CK1 check (id3 > 2), constraint CK2 check (id1 > id2), ) I can find the dependencies of CK1 by querying select * from sys.check_constraints. The parent_column_id will return the correct answer of 3. The However, CK2 is a […]

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