sql-server

SQL Server 2008: How to find trailing spaces

How can I find all column values in a column which have trailing spaces? For leading spaces it would simply be select col from table where substring(col,1,1) = ' '; ...

Copy whole SQL Server database into JSON from Python

I facing an atypical conversion problem. About a decade ago I coded up a large site in ASP. Over the years this turned into ASP.NET but kept the same database. I've just re-done the site in Django and I've copied all the core data but before I cancel my account with the host, I need to make sure I've got a long-term backup of the data s...

Microsoft Sync Framework between sql CE and sql 2008 with change tracking

Microsoft Sync Framework: Sql CE and sql 2008 with change tracking option. I am facing a problem, when i have a record inserted in sql CE and it needs to upload on sql 2008 with uploadonly direction. The server sync process gives clientInsertServerInsert conflict and it is impossible that server can add new row to this table. Anybody ...

SQLServer:Namespaces preventing access to query data

Hi A beginners question, hopefully easily answered. I've got an xml file I want to load into SQLServer 2008 and extract the useful informaiton. I'm starting simple and just trying to extract the name (\gpx\name). The code I have is: DECLARE @x xml; SELECT @x = xCol.BulkColumn FROM OPENROWSET (BULK 'C:\Data\EM.gpx', SINGLE_BLOB) AS ...

How do I keep a table in Sync across 4 db's to be used in SQL Replication Filtering?

I have a Win Form, Data Entry application that uses 4 separate databases. This is an occasionally connected app that uses Merge Replication (SQL 2005) to stay in Sync. This is working just fine. The next hurdle I am trying to tackle is adding Filters to my Publications. Right now we are replicating 70mbs, compressed, to each of our 150 ...

SQL Database Mirroring and your web application

You have two servers when you perform a SQL Server database mirroring You have 1 primary database and 1 mirror database Do you need to make any changes to web application to tell it that your using database mirroring? If not how does your web application know which database to use when the primary database fails? ...

Can I delete a differential backup from SQL Server 2005?

I often like to create backups when testing the software I work on, and will sometimes create a differential backup if I want to be able to get back to multiple previous states. However, sometimes I realize that I forgot one thing I wanted to include in a differential backup, or I no longer need a previous differential backup. Sometime...

Linq to SQL Web Service XML

I built a .NET web service connecting to an SQL Server database. There is a web service call GetAllQuestions() that will not change. I saved the result of GetAllQuestions to GetAllQuestions.xml in the local application folder and set it to content. Normally I would get the result of the web service like this: var myService = new SATSer...

Dynamic SQL to generate column names?

I have a query where I'm trying pivot row values into column names and currently I'm using SUM(Case...) As 'ColumnName' statements, like so: SELECT SKU1, SUM(Case When Sku2=157 Then Quantity Else 0 End) As '157', SUM(Case When Sku2=158 Then Quantity Else 0 End) As '158', SUM(Case When Sku2=167 Then Quantity Else 0 End) As '167' FROM Ord...

How can I set a Microsoft SQL field as identity but to START with a certain number?

Pretty newbie question. Thanks for helping. ...

Can LINQ-to-SQL omit unspecified columns on insert so a database default value is used?

I have a non-nullable database column which has a default value set. When inserting a row, sometimes a value is specified for the column, sometimes one is not. This works fine in TSQL when the column is omitted. For example, given the following table: CREATE TABLE [dbo].[Table1]( [id] [int] IDENTITY(1,1) NOT NULL, [col1] [nvarch...

What is happening in this T-SQL code? (Concatenting the results of a SELECT statement)

I'm just starting to learn T-SQL and could use some help in understanding what's going on in a particular block of code. I modified some code in an answer I received in a previous question, and here is the code in question: DECLARE @column_list AS varchar(max) SELECT @column_list = COALESCE(@column_list, ',') + 'SUM(Case When Sku...

What about the Sql transaction log

Hi, i always thought that the sql transaction log keeps track of all the transactions done in the database so it could help recovering the database file in case of a unexpected power down or something like that So then, in normal usage, when the data is committed and written to disk, it is cleared because all the data is nice and safe i...

Is it possible to access the queries in a file created by SQL Server?

Is it possible to access the queries and procedures in a file created by SQL Server without installing SQL Server? Problem is that I am having problems to install the SQL server / Express version. ...

SQL Server 2008 Table Maintenance - Rebuild, Reorganize, Update Stats, Check Integrity etc HELP!

I'm migrating a ~15GB database from SQL Server 2005 to a new server running SQL Server 2008, and along with that I need to create all the new Maintenance Plans. I can take care of all the backup stuff, but the table maintenance baffles me some. Does anyone have any input on how often I should (or how often you do would suffice too) the...

SQL Server 2008 - Shrinking the Transaction Log - Any way to automate?

I went in and checked my Transaction log the other day and it was something crazy like 15GB. I ran the following code: USE mydb GO BACKUP LOG mydb WITH TRUNCATE_ONLY GO DBCC SHRINKFILE(mydb_log,8) GO Which worked fine, shrank it down to 8MB...but the DB in question is a Log Shipping Publisher, and the log is already back up to some 5...

How can I do a left outer join where both tables have a where clause?

Here's the scenario: I have 2 tables: CREATE TABLE dbo.API_User ( id int NOT NULL, name nvarchar(255) NOT NULL, authorization_key varchar(255) NOT NULL, is_active bit NOT NULL ) ON [PRIMARY] CREATE TABLE dbo.Single_Sign_On_User ( id int NOT NULL IDENTITY (1, 1), API_User_id int NOT NULL, extern...

Realizing program with decision tree logics

The system realizes a game “Think animal”. Main use case is: 1. System offers user to think about any animal and the system will try to guess it 2. The system starts asking questions from the start of decision tree. Ex., “Question: It has fur?”, and provides possible answers – yes or no. 3. If the user answers Yes, the system procee...

SQL Server 2008 Dead lock issue

I got into a deadlock issue where I am struggling find the root-cause...The Deadlock graph suggests that an UPDATE statement became the victim over a SELECT statement... What puzzles me is that the UPDATE statement is trying to acquire an index on some other table that is never referred in update statement... This is how my UPDATE state...

Physical operators in SQL Server execution plans: what are rebinds, rewinds and number of executions?

I'm trying to understand physical operators in SQL Server execution plans. This page is quite helpful: http://technet.microsoft.com/en-us/library/ms191158.aspx SSMS 2008 shows some physical operator properties that are not displayed in SSMS 2005: Estimated Number of Executions and Number of Executions. But what do these actually mean, ...