sql-server

String Comparison differences between .NET and T-SQL?

In a test case I've written, the string comparison doesn't appear to work the same way between SQL server / .NET CLR. This C# code: string lesser = "SR2-A1-10-90"; string greater = "SR2-A1-100-10"; Debug.WriteLine(string.Compare("A","B")); Debug.WriteLine(string.Compare(lesser, greater)); Will output: -1 1 This SQL Server code: ...

Not able to import large flat file into SQL Server 2008 table

I have an 18GB flat file (40,000,000 records), with fixed column widths (no field terminators), which I would like to read into a SQL Server 2008 R2 table. In addition to the text file with the data, I was given an Excel document with the field names and lengths. There are 270 fields with 465 total characters per record (per row). Using ...

Need to capture database name when error occurs with sp_msforeachdb

I am running a dynamic sql command with sp_msforeachdb for each database. However the command bombs for a certain database. How is '?' used to display the database name when the error happens? I tried using it in a Catch statement but my syntax is wrong. ...

sql 2005 grouping data that is dynamic

I have data that looks like this Investor Contact IBM James IBM Dean IBM Sean Microsoft Bill Microsoft Steve I need the data to look like this Investor Contact IBM James,Dean,Sean Microsoft Bill,Steve OR if the above is impossible Investor Contact1 Cont...

Is there any way to index a varchar column as a datetime?

I'm querying a varchar column that contains all valid datetimes. In the query, I cast the column to datetime. Keep in mind, changing the column's datatype definition to datetime is not an option. Just trust me, it's not an option. Through query analysis, I see that the query would be much faster if I could add an index on this column....

Resource locking in SQL Server Management Studio

I've noticed that when viewing query results in a grid in SQL Server Management Studio, it often causes resource locking on the server, preventing other queries from running. Why does this happen, when I'm only opening the table for viewing and not for editing? Disconnecting the query window from the server releases the resources. I assu...

Convert tabular data to XML using SQL Server

I have a flattened table that contains columns that represent groups that need to be displayed in XML. Example data: Market, Label, Style, Type XXX, YYY, JJJ, 111 XXX, YYY, JJJ, 222 XXX, YYY, JJJ, 333 XXX, YYY, JJJ, 444 XXX, YYY, LLL, 111 XXX, YYY, LLL, 222 XXX, YYY, LLL, 333 ...

Determining row changes since last access in SQL Server

We have a multiuser system with users saving to a central SQL Server 2005 database. We have encountered an issue where a user refreshes in changes from the db while another user saves new data. The way we are currently collecting the changes is we have a timestamp column on each table which is filled at every row insert/update. Another u...

System.OutOfMemoryException when binding a gridview to a datatable having more then 400000 records

Dear, I am facing system.outofmemmory exception when binding a gridview with a datatable having more then 400000 records please find the below sample code for the same GridView gv = new GridView(); this.EnableViewState = false; gv.DataSource = (DataTable)dt; gv.DataBind(); Kindly help me to overcome in this situation is there any lim...

SqlConnection.ClearAllPools, what is cleared?

I have an application which uses SqlConnection.ClearAllPools to close all connections before dropping a database. There is a case where a connection is still there. This connection had been created in another application domain. So I wonder which connections are closed by SqlConnection.ClearAllPools? Only the connections opened by t...

Sending parameters into stored procedure in SQL Server 2008

I have this stored procedure Usp_temp @temp nvarchar(50) Where city in (@temp) and I try to send a num of parameters like this Usp_temp '1,3,5' what is the right way to do this? ...

Create SQL Server database programmatically with C#

I'm trying to follow this example but I get an Exception related to the connection string telling me that the server was not found or was not accessible. The tutorial itself tells me on step 5 to "Change the connection string to point to your computer running SQL Server". I don't know if my SQL Server is running or not and if it is I don...

sql server vs postgres in .net SqlConnection vs NpgsqlConnection

I'm experimenting with postgres and sql server the same query in sql server gives me: CPU time = 31 ms, elapsed time = 800 ms. and in postgres: 38 ms but when I do the same query via .net using SqlConnection,SqlCommand and NpgsqlConnection,NpgsqlCommand the sqlserver is 30% faster can anyone explain this ? ...

Batch updation in SQL server 2008

hi friends..... I have an application run on an enterprise having head office and branches. Each branch has separate local server and DB. The master server and DB is updated daily by batch updation . How can i overcoming the id conflict in such situation. Eg: i have a record with ID 10 on branch A Also a transaction with referen...

rank items in sql by dates

I have movies table with movieID,movieName and movieDate. I want to select first all movies which added in last 24 hours and order them by date and the rest order by newid(). ie. 1 babylon 28/09/2010 16:00 2.12 monekys 28/09/2010 8:00 3.se7en 25/09/2010 5:00 4.snatch 26/09/2010 18:00 How can i achieve it? Final answer which is a c...

Full-text Search on documents and related data mssql

Currently in the middle of building a knowledge base app and am a bit unsure on the best way to store and index the document information. The user uploads the document and when doing so selects a number of options from dropdown lists (such as category,topic,area..., note these are not all mandatory) they also enter some keywords and a d...

Tsql: can i use a variable as database reference

Hi, i want to accomplish this: update @sourceDatabase.dbo.PredictedPrices and then set @sourceDatabase as a variable. But i'm not allowed? Incorrect syntax near '.'. Is there another way? ...

Connecting to database over loopback adapter with SQL Management Studio under Windows 7

Hi all, following situation: I am running a MSSQL Server 2005 on a virtual pc. The vpc(Windows Server 2003) and my host system(Windows 7) are connected with a loopback network adapter. I can ping the vpc and I can access the web application running on the vpc. But I am not able to connect to the database from my host system with Sql Ma...

Recommended approach to merging two tables

I have a database schema like this: [Patients] [Referrals] | | [PatientInsuranceCarriers] [ReferralInsuranceCarriers] \ / [InsuranceCarriers] PatientInsuranceCarriers and ReferralInsuranceCarriers are identical, except for the fac...

bi-directional replication sql server 2008

hi all i am asking about any useful data or links to get to know about bi-directional Replication thnx ...