sql-server

SQL - Iterating through table records

Hello, I have created user-defined function that converts a comma-delimited string into a table. I execute this function like so: select [String] as 'ID' from dbo.ConvertStringToTable('1,2,3,4') The results from this query look like the following: ID -- 1 2 3 4 In reality, I want to iterate through each of the rows in this table. ...

Implementing custom fields with ALTER TABLE

We are currently thinking about different ways to implement custom fields for our web application. Users should be able to define custom fields for certain entities and fill in/view this data (and possibly query the data later on). I understand that there are different ways to implement custom fields (e.g. using a name/value table or us...

Indexing table with duplicates MySQL/SQL Server with millions of records

I need help in indexing in MySQL. I have a table in MySQL with following rows: ID Store_ID Feature_ID Order_ID Viewed_Date Deal_ID IsTrial The ID is auto generated. Store_ID goes from 1 - 8. Feature_ID from 1 - let's say 100. Viewed Date is Date and time on which the data is inserted. IsTrial is either 0 or 1. You can ignore Order_ID an...

How to get Database names from given Sql Server in LINQ

I have DropDownList displays all server present in my network I want to populate the databse names when i changed it into another dropdown I want a LINQ query to get this. ...

Analysis Services Plugin using DMPluginWrapper with C#

I'm developing a desicion tree algorithm (CHAID) to be integrated as a plugin in SQL Server 2008 Analysis Services. It is almost done. The only thing that's missing in my implementation is the capability of testing the algorithm accuracy using any of the Mining Accuracy Chart. When I try to use these features, in my Visual Studio Busine...

How can I efficiently compare my data with a remote database?

I need to update my contacts database in SQL Server with changes made in a remote database (also SQL Server, on a different server on the same local network). I can't make any changes to the remote database, which is a commercial product. I'm connected to the remote database using a linked server. Both tables contain around 200K rows. M...

SQL Server - Limit the databases view based on login

Hi there, I have a situation where I want to limit the database view per user login. For example: I have 3 databases in my SQL Server instance called MyDB, UserDB, RestrictedDB. I then create a 2 logins; User1 and User2. I then did a DENY VIEW ANY DATABASE TO [User1] and then DENY VIEW ANY DATABASE TO [User2]. I then made User1 the ow...

Split Address column into separate columns in SQL view

I have an Address column in a table that I need to split into multiple columns in a view in SQL Server 2005. I need to split the column on the line feed character, chr(10), and there could be from 1 to 4 lines (0 to 3 line feeds) in the column. Below are a couple of examples of what I need to do. What is the simplest way to make this h...

SyncFramework sync anchor not converted correctly into a valid DateTime string

I'm using SyncFramework 1.0 for syncing a SqlCe 2005 database with SqlServer 2005. I'm setting the Sync anchor like this... CommandText = "Select @sync_new_received_anchor = GETUTCDATE()", but syncframework converts this value to a string with too many decimal places.... exec sp_executesql N'SELECT [Company], [ServiceAreaId], [Cost...

SQL Server ETL process transaction logs

hi, is it ok to set recovery mode simple in a staging db for an ETL process... The customer is not even doing a regular backup! So what's the point in keeping the transaction logs... I propose to organize a daily backup after the bulk import and that's it... Anything against this plan? Also the transaction logs were at 80gb after 3 we...

Assign role of db_denydatawriter to user dbo

When I try to do this I receive the following error message: Add member failed for DatabaseRole 'db_denydatawriter'. (Microsoft.SqlServer.Smo) ADDITIONAL INFORMATION: An exception occurred while executing a Transact-SQL statement or batch. (Microsoft.SqlServer.ConnectionInfo) Cannot use the reserved user or role name 'dbo'. (...

Replication to maintain data integrity

We have two situations: We have a database server that contains tables of job titles. Those job titles need to be accessed by a database on another server. We have established a linked server connection and everything works well. Problems: There can be no foreign key referential integrity because the tables are physically stored on...

mysql @@identity vs sql-server last_insert_id()

Am I correct in understanding that mysql's LAST_INSERT_ID() function doesn't reset between insert attempts (as @@identity does in sql-server)... that if the immediately preceding insert operation fails, LAST_INSERT_ID() will return the pk of whatever the pk of that connection's last insert to any table with an auto-incrementing primary k...

Make data in database read-only but allow schema changes

This is a clarification of an earlier question I asked. It is sufficiently different from that question that I thought it could stand on its own. I create snapshots of a production database semi-annually. Users are then able to view historical data by switching the back-end database from the front-end GUI. Because it is historical da...

Matching a field with variable number of leading zeroes in SQL Server table

I have a situation where I have an incoming data value that may or may not have leading zeroes. I need to match that to a field/row in a SQL Server table. The field value in the SQL Server database may or may not have leading zeroes as well. So, I might have: incoming = 5042800138 and the value in db can be any of 5042800138, 05042800...

Is it possible to set an index inside a XML column on SQL Server 2005 / SQL Server 2008?

Hi, I have an application that stores xml documents inside a column on SQL Server. The structure of the XML document is similar to the one below: <document> <item> ... <phoneNumber>0123456789</phoneNumber> .... </item> <item> ... <phoneNumber>9876543210</phoneNumber> .... ...

Is it possible to create a temp table on a linked server?

I'm doing some fairly complex queries against a remote linked server, and it would be useful to be able to store some information in temp tables and then perform joins against it - all with the remote data. Creating the temp tables locally and joining against them over the wire is prohibitively slow. Is it possible to force the temp tab...

Find out the number of connections to tomcat server

I have a Java/JEE web application deployed on Tomcat Server 5.5.17. I want to know the number of clients which are connected to the server. How can we find it out? ...

SQL Server: Improve PROCEDURE without using CURSOR

I am looking for a way to write the below procedure without using a CURSOR or just a better performing query. CREATE TABLE #OrderTransaction (OrderTransactionId int, ProductId int, Quantity int); CREATE TABLE #Product (ProductId int, MediaTypeId int); CREATE TABLE #OrderDelivery (OrderTransactionId int, MediaTypeId int); INSERT INTO #P...

Will Schema change of a replicated object will affect replication?

We have two DB instances in our SQL 2000 server and some 10 tables from DB 'A' is replicated in DB 'B'. Whatever change we make in DB 'A' tables are replicated to DB 'B' tables. We have added a column to one of the table in DB 'A'. Do we need to alter the table in DB 'B' also? Or else it depends on how the replication was setup(which i d...