sql-server

How to select distinct in SQl Server 2008 but for only one field out of many?

I have a query: SELECT Content.content_name, Language2.Name, Language2.language_id, Content.id, Content.content_description, FROM Language AS Language2 LEFT JOIN contents AS Content ON (Language2.language_id = Content.language_id) How do I select only the distinct content_name? ...

Using JDBC driver to connect with Sql Server 2008

I'm using following code to connect with Sql Server 2008: Connection con = null; CallableStatement stmt = null; ResultSet rs = null; try { SQLServerDataSource ds = new SQLServerDataSource(); ds.setIntegratedSecurity(false); ds.setServerName("localhost"); ds.setInstanceName("MSSQLSERVER2008"); ds.setPortNumber(1433);...

Choosing connectionstring in VB.NET application at startup

I have a VB.NET application with a connection to an SQL Server 2003. On the server there are two databases, MyDatabase and MyDatabase_Test. What I would like to do is to show a dialog when the program starts that let's the user choose which database to use. My idea is to create a new form as the starup form that sets this property and th...

updateBinaryStream on ResultSet with FileStream

If I try to update a FileStream column I get following error: com.microsoft.sqlserver.jdbc.SQLServerException: The result set is not updatable. Code: System.out.print("Now, let's update the filestream data."); FileInputStream iStream = new FileInputStream("c:\\testFile.mp3"); rs.updateBinaryStream(2, iStream, -1); rs.updateRow(); iStr...

Why is TransactionScope using a distributed transaction when I am only using LinqToSql and Ado.Net

We are having problems on one machine, with the error message: "MSDTC on server XXX is unavailable." The code is using a TransactionScope to wrap some LingToSql database code; there is also some raw Ado.net inside of the transaction. As only a single sql database (2005) is being accessed, why is a distributed transaction being ...

Is there a way to only backup a SQL 2005 database structure fully, but only the data in a certain set of schemas?

I have several schemas in my database, and the largest one ("large" meaning disk space consumed) is my "web" schema which is a denormalized copy of data in the operational schemas. This denormalized data is able to be reconstructed at anytime, and is merely there for extremely fast read purposes. Since the data is redundant, and VERY...

How to retrieve unicode data stored directly in non-unicode field as varchar format in sql server

I have to create a C# application which displays unicode data in a textbox. But the SQL server column storage has varchar data which contains unicode data. But since varchar is non-unicode based it displays character strings like "????????". Well the problem i am facing is i cant change the column type as there are other dependent app...

How I should use BIT in SQL Server 2005

Regarding to SQL performance. I have a scalar valued function for checking some specific condition in base, it returns BIT value for True or False. I now do not know how I should fill @BIT parameter If I write. set @bit = convert(bit,1) or set @bit = 1 or set @bit='true' function will work anyway but I do not know which met...

How can I turn a bunch of rows into aggregated columns WITHOUT using pivot in SQL Server 2005?

Here is the scenario: I have a table that records the user_id, the module_id, and the date/time the module was viewed. eg. Table: Log ------------------------------ User_ID Module_ID Date ------------------------------ 1 red 2001-01-01 1 green 2001-01-02 1 blue 2001-01-03 2 green 20...

Find all the varchar() fields in sql server?

Hi, Is it possible to find all the varchar() columns in my database? I am using SQL Server 2008 and would like to get the list in SQL server management console. JD. ...

How to find Expr#### in Execution Plan

When looking at the actual execution plan for a query in SQL Server Management Studio (SSMS), how do I determine what an expression such as Expr1052 represents? When I identify the costly parts of the query and look at the properties of that operation, there are often references only to these Expressions, or scalar operators. I want to...

Get list of elements and their values from an untyped xml fragment in T-SQL

Similiar to question: http://stackoverflow.com/questions/2266132/how-can-i-get-a-list-of-element-names-from-an-xml-value-in-sql-server How would I also get the values for the list of elements. For example: <Root> <A>a1</A> <B>b1</B> <C>c1</C> </Root> Would return Element | Value A | a1 B | b1 C | c...

Having trouble using 'AND' in CONTAINSTABLE SQL SERVER FULL TEXT SEARCH

I've been using FULL-TEXT for awhile but I cannot seem to get the most relevant results sometimes. If I have an field with something like "An Overview of Pain Medicine 5/12/2006" and a user types "An Overview 5/12/2006" So we create a search like: '"An" AND "Overview" AND "5/12/2006"' - 0 results (bad) '"Overview" AND "5/12/2006"' - 1 ...

For SQL select returning more than 1 value, how are they sorted when Id is GUID?

I'm wondering how SQL Server orders data that is returned from a query and the Id columns of the respective tables are all of type uniqueidentifier. I'm using NHibernate GuidComb when creating all of the GUIDs and do things like: Sheet sheet = sheetRepository.Get(_SheetGuid_); // has many lines items IList<SheetLineItem> lineItems = sh...

When does a query/subquery return a NULL and when no value at all?

a) If a query/subquery doesn’t find any matching rows, then it either returns NULL or no value at all, thus not even a NULL value. Based on what criteria does a query/subquery return a NULL and when doesn’t it return any results, not even a NULL value? b) I assume a scalar subquery will always return NULL, when no matching rows are foun...

Client-side Replication for SQL Server?

I'd like to have some degree of fault tolerance / redundancy with my SQL Server Express database. I know that if I upgrade to a pricier version of SQL Server, I can get "Replication" built in. But I'm wondering if anyone has experience in managing replication on the client side. As in, from my application: Every time I need to creat...

Separating weakly linked database schemas

I've been tasked with revisiting a database schema we designed and use internally for various ticketing and reporting systems. Currently there exists about 40 tables in one Oracle database schema supporting perhaps six webapps. However, there's one unifying relationship amongst them all: a rooms table describing the room. Room name, pu...

SQL Server: How do I delimit this data?

declare @mydata nvarchar(4000) set @mydata = '36|0, 77|5, 132|61' I have this data that I need to get into a table. So for Row1 columnA would be 36 and columnB would be 0. For Row2 columnA would be 77 and columnB would be 5 etc. What is the best way to do this? Thanks ...

SQL Server 2005: When copy table structure to other database "CONSTRAINT" keywords lost

Snippet of original table: CREATE TABLE [dbo].[Batch]( [CustomerDepositMade] [money] NOT NULL CONSTRAINT [DF_Batch_CustomerDepositMade] DEFAULT (0) Snippet of copied table: CREATE TABLE [dbo].[Batch]( [CustomerDepositMade] [money] NOT NULL, Code for copy database: Server server = new Server(SourceSQLServ...

Replication - syncronizing most of the data some of the time

I have some data that isn't properly "partitioned" (for lack of a better word). All inserts, processing and reporting happen on the same table. The bulk of the processing happens not long after the insert and not long after that it becomes immutable (we're talking days). I could do all inserts and processing on a new table that I repl...