sql-server-2005

How can I stop System.OutOfMemoryException on bulk insert.

Hi I am bringing about 100000 records into memory cleaning the data and inserting into a new table. After inserting around 2000 records I get the following exception. A first chance exception of type 'System.OutOfMemoryException' occurred in Iesi.Collections.DLL A first chance exception of type 'FluentNHibernate.Cfg.FluentCon...

Escape Character in SQL

Hi, Please forgive me as I am a bit of an sql noob. I am trying to do an insert using the following but am having a problem with the apostrophes. I have a lots of records to insert but many have the same problem. Is there a way of escaping them? INSERT INTO [dbo].[tb_Chefs] ([ChefHotelID], [HotelID], [ChefID], [Position], [Gro...

How to get Date diffrence in hh:mm format In Select Query Sql 2005

Hi I am trying to get the the result of in time and out time from dates but it returns only hours using following select Query as follows SELECT DATEDIFF(Hh,InTime,OutTime) as Diff_time from EmpLogTable and i need result in HH:MM Suppose my in time is 11 am and out is 5.49pm so o/p would be 6.49 but using above select query i ...

C# and SQL Server 2005: Return value and update in one batch

Hi, Just curious whether it is reliable way to do following: I need to get some value and then update it, optimally in one batch. SELECT X FROM Y //will it be returned if executed in one batch? UPDATE Y SET X... Executed as Reader? I am not sure whether it will return if there is the UPDATE statetement. And one extra question, what if...

C# SqlCommand - cannot use parameters for column names, how to resolve?

Hi, Is there any way how to do that? This does not work: SqlCommand command = new SqlCommand("SELECT @slot FROM Users WHERE name=@name; "); prikaz.Parameters.AddWithValue("name", name); prikaz.Parameters.AddWithValue("slot", slot); The only thing I can think of is to use SP and declare and set the variable for the column. Seems to me ...

Selecting a user's friend's events

I have these information : Table "Users" => **Id** **Name** 1 a 2 b 3 c 4 d 5 e Table "Friends" => **SenderId** **ReceiverId** **State** 1 2 x 2 3 ok 3 1 ok 3...

SQL - Is it better to do a subquery here or an extended WHERE clause?

The CUST table below will be joined with ~10 tables. For this subquery in particular, am I better off simply joining up directly with the Customer table and moving the subquery's 4-part WHERE clause to the main query's WHERE clause? I'm primarily wondering if it is possible to cut down on the amount of processing that SQL Server has to...

How To Move an Updated Record into a History Table?

I have the following table: CREATE TABLE FE_USER ( userid int identity (321,4) CONSTRAINT userid_pk PRIMARY KEY, username varchar(40) ); Its corresponding history table is CREATE TABLE FE_USER_HIST ( userid int, username varchar(40), v_action varchar(50) ); Every time an insert or update is occurred on FE_USER t...

Temporary Table Scope

I am making use of temporary tables #tempTable in my stored procedure - that I make use to run my ASP.net Reports (Reporting services) I am doing something like eg. Code SELECT * INTO #tempTable FROM Contacts WHERE ContactID < 10 Then I use something like SELECT o.* FROM #tempTable t INNER JOIN Orders o ON t.ContactID =o.ContactID ...

How Can I Export a Record Set to Excel from SQL Server 2008?

I have a department table filled with records. I would like to run a query or use the management studio interface to export department records to an excel file. Format is not an issue, i just want to dump the records into excel. I know i can copy and paste, but this is not what i'm looking for. ...

SQL Server 2005: Getting error when setting auto increment on one of two primary keys

hi I am getting an error "Cannot insert explicit value for identity column in table 'table' when IDENTITY_INSERT is set to OFF." The table has two primary key, one is set to auto-increment, one is set with value i passed into. Is this possible in SQL Server 2005? or am i missing something? Thanks alot in advance. ...

T-SQL: find an empty column

Hi, In my table there are 10 columns used for storing "items" (game server). When an user picks the item up, it should loop through columns 0-9 (with names "I0".."I9") and returns once the column in current row is empty. I cannot figure out how to do it on the SQL server side. I can only think of IF EXISTS for each column but that is not...

SQL - looping through columns, once empty is found, update it

Hi, I started similar thread but as the problem is more difficult, I would like to start from scratch. Imagine there are 10 inventory slots (in DB they are columns in the user's row). When an users picks an item up, it should be placed into the first empty column (it gets updated). But how to do the looping through the columns (except fo...

Connect Windows-based application to web based database SQL Server

Is it possible to connect a Windows-based C#.net application to a WEB based SQL Server 2005? Any help considered lot for me. thanks ravi ...

how to check if a type of row exists in a table

Hi I have an order table and a payment table which are linked by order_num. I would like to get entries from order table who have entries in the payment table of PaymentType 'A' as well as PaymentType 'B' and their amounts match. Example order number 411 should only be returned to me if it has at least two payments and one of them is p...

Reduce SQL Server table fragmentation without adding/dropping a clustered index?

I have a large database (90GB data, 70GB indexes) that's been slowly growing for the past year, and the growth/changes has caused a large amount of internal fragmentation not only of the indexes, but of the tables themselves. It's easy to resolve the (large number of) very fragmented indexes - a REORGANIZE or REBUILD will take care of t...

UTF8 problem sql server

I have some utf8 data which I would like to bulk insert (sql server 2005). I am using the CODEPAGE 65001: BULK INSERT #bla FROM 'D:\bla.txt' WITH ( CODEPAGE=65001, FIELDTERMINATOR = '\t', ROWTERMINATOR = '\n' ) Unfortunatly strings like this: Erdağı end up being stored like this: Erda?? Do I use the wrong code pag...

Copy from SQL Server 2005 to SQL Server 2008 causes x2 data space #SQLHelp

A colleague of mine is copying data from SQL Server 2005 to SQL Server 2008. The destination database lives on a SQL Server 2008 instance but is set to Compatibility Level 90. The source database lives on a SQL Server 2005 instance and is set to Compatility Level 90. He is using SQL Server Integration Services 2008 to perform the co...

SQL Cursor/Population Question

So here's the setup. I have two tables: CREATE TABLE dbo.TmpFeesToRules1(Name varchar, LookupId int) CREATE TABLE dbo.TempFeesToRules2(FeeId int, Name varchar) I have a third table called 'Fee' in the database that's already created. I want to populate dbo.TmpFeesToRules1 'Name' field with the DISTINCT 'Name' from 'Fee'. Would I do th...

Does Entity Framework 4 work with SQL Server 2005?

Does ADO.NET Entity Framework 4 work with SQL Server 2005? I'm having trouble getting EF to work and I'm wondering if it's because of our version of SQL Server. ...