sql-server

How to refresh database data only in SQL Server

So I want to copy just the data from a Prod database (SQL 2005) down to my local machine (SQL 2005 & SQL 2008 Management Studio installed). The problem is I'm running into foreign key constraints that are causing the task/scripts to fail. I can get by these errors if I import certain tables first, but is there an easier way to do this a...

Unable to construct an entity (complex) object from a query

Hey, I am very new to entity, sql, c#, and asp.net so this might be something easily fixed. I am attempting to display all the inactive products stored in my table called products in a datagrid. var productQuery = from b in solutionContext.Version where b.Product.Name == search && b.Product.ActiveNumber > b.VersionNu...

Is READ UNCOMMITTED / NOLOCK safe in this situation?

I know that snapshot isolation would fix this problem, but I'm wondering if NOLOCK is safe in this specific case so that I can avoid the overhead. I have a table that looks something like this: drop table Data create table Data ( Id BIGINT NOT NULL, Date BIGINT NOT NULL, Value BIGINT, constraint Cx primary key (Date, I...

Convert Military time to string representation

I have an column declarated as int (called HourMil) wich store the time in military format. i need convert this values to an formated string (HH:MM) example HourMil = 710 -> must be 07:10 HourMil = 1305 -> must be 13:05 Actually i am using this code (and works ok) for convert the column HourMil to the string representation. SELEC...

T-SQL For Each Alternative?

I need to take data from one table and import it into another table. In pseudocode, something like this: For Each row in table1 If row.personid is in table2 then update table2.row Else insert row into table2 End If Next What is the best way to do this in T-SQL? As I understand it T-SQL doesn't support For Each..Next, so what alt...

not including null values in sql join

Hi, I have two tables CustomerAddress(CustomerId, City, Country) and CustomerTransactions(TransactionId, CustomerId, CustomerContact). Here are the values in the tables: For CustomerAddress: 1001, El Paso, USA 1002, Paris, France 1003, Essen, Germany For CustomerTransactions: 98, 1001, Phillip 99, 1001, NULL 100, 100...

Repeatedly execute a stored procedure

I have a situation where I need to repeatedly execute a stored procedure Now this procedure (spMAIN) has a cursor inside which looks for a value from a table as T1,which has the following structure ID Status ---- -------- 1 New 2 New 3 success 4 Error now the cursor looks for all rows with a status of 'New' Now...

Dynamic Database connection

I have multiple client databases that I need to hit on the fly and I am having trouble getting the code I have to work. At first I was just storing a connection string in a clinet object in the db, pulling it out based on logged-in user, and passing it to linq data context constructor. This works fine in my development enviorment but is ...

SSRS report combine data sources and generate csv

I am new to ssrs. I have a report that gets data from two databases. I can create two datasets that connect to two different databases. The databases are third party and I cannot create stored procedures on the databases. My issue is that I have to combine the data from the two queries. Please help me with this issue or point me to loca...

How Serializable works with insert in SQL Server 2005

G'day I think I have a misunderstanding of serializable. I have two tables (data, transaction) which I insert information into in a serializable transaction (either they are both in, or both out, but not in limbo). SET TRANSACTION ISOLATION LEVEL SERIALIZABLE BEGIN TRANSACTION INSERT INTO dbo.data (ID, data) VALUES (@Id, data) INSERT I...

Dynamically Specify Linked Server and DB Names in Stored Procedure

I have the same query in a stored procedure that needs to be executed on different servers and databases according to parameters. How can I arrange this without exec or sp_executesql? I'm using SQL Server 2008. Thank you. UPDATE I've found some links http://www.eggheadcafe.com/software/aspnet/29397800/dynamically-specify-serve....

Automatically attach SQL Server database during/after installation

Please tell me how can we attach SQL Server database (SQL Server 2005) during installation or after installation using c#.net (desktop application). We can create a form to get details of connection string (user id, pass, server name etc..) . please tell me how can we automatically attach database with SQL Server using .net ...

fastest way to exchange data with SQL Server 2008

I have a native C++ windows client application and a SQLServer 2008 server instance. I need to transfer a whole bunch of data both ways. I'm currently using SOCI (http://soci.sourceforge.net/) with an ODBC backend, but have already identified several performance problems with it and would like to try alternatives. SQL data types used are...

In SQL Server, how can I insert data into a table that has just one column which is of identity type?

In SQL Server, how can I insert data into a table that has just one column which is of identity type? Such as insert into the following table t. How can I write the insert statement? CREATE TABLE t ( id INT IDENTITY(1, 1) PRIMARY KEY ) Great thanks. ...

Multilevel nested product categories display with asp.net and sql server?

I have a product category table with the following fields: cat_id (PK) Cat_name Cat_desc Parent_Cat_Id Now when a user wants to add a product he should be able to select multiple categories from a listbox(multiselection enabaled). But to let the user know the hierarchy of the categories, I need to display them in the following style...

Output in one row by using stuff function

Hi, Im using the following query and its giving me the following ouput. What i want is one row although i tried to use cast function but not much success, Can some one advise how i can achive this MS SQL server as in oracle we do have certain functions like stragg Output : I'm getting the following result Tenancy No Property NO userco...

How to do a Postgresql subquery in select clause with join in from clause like SQL Server?

I am trying to write the following query on postgresql: select name, author_id, count(1), (select count(1) from names as n2 where n2.id = n1.id and t2.author_id = t1.author_id ) from names as n1 group by name, author_id This would certainly work on Microsft SQL Server but it does not at all on p...

Duplicate table on 2 different servers (MS SQL 2000/2008)

Ok here is the thing: I have an old MS SQL 2000 server, and this one will keep running. however for a new website i have a SQL 2008 server. I need 3 tables from the old server (lets call it www.oldserver.com) to be on the new server too. the data on the old server still changes daily. I would like to update the tables immediately w...

error come to execute the stored procedure using with open xml in sql server

Hi, i execute the below stored procedure.but it shows the error. The error is 'Incorrect syntax near '.'.i.e error shows in 'xmlFields.Country' please look this stored procedure also and help me thanks, in advance create procedure sp_SuUpdateSUADUsersStatus ( @FinalEMPCode nvarchar(50), @xmlFields NTEXT ) AS DECLARE @CityI...

Get all related products based on their full-text search relationship

I have a Product table with the fields Id, Title, Description, Keywords (just comma separated list of keywords). Table is full-text indexed. When I view one product, I do a query and search the full-text catalog for any related products based on the Keywords field. select * from Products where Contains(Products.*, @keywordsFromOnePr...