sql-server

How can I Insert/Update into two related tables in one command?

A database exists with two tables Data_t : DataID Primary Key that is Identity 1,1. Also has another field 'LEFT' TINYINT Data_Link_t : DataID PK and FK where DataID MUST exist in Data_t. Also has another field 'RIGHT' SMALLINT Coming from a microsoft access environment into C# and sql server I'm looking for a good method of import...

SQL Date Compare by only using Date not Time

This was originally going to be a question about how to implement this because I was stuck at a certain part but I am now curious as to why this was happening in the first place. I needed to compare only the dates not the time which wouldn't have been a problem if the times didn't differ. The code below shows the query I was originally t...

How can I force TransactionScope to use the same connection across Database calls?

Good Morning All, I have code similar to the following try{ using(var tx = new TransactionScope()){ var Xupdated = someDao.DoSomeUpdateQuery(); //this dao uses MS Data ApplicationBlock var Yupdated = someDao.DoSomeOtherUpdateQuery(); //this dao also uses MS Data ApplicationBlock if(Xupdated && Yupdated) ...

UUID returning as bytes_le from MS SQL

I'm querying a table from my Django app, but whenever I do a query on one specific table, I am getting the UUID column returned as a bytes_le style UUID instead of a workable string representation. Now, I know I convert it using uuid.UUID(bytes_le=value), but I'm using this query to populate a WTForms QuerySelectField, so I don't really...

sql server Restore Database

Backed up a database from my hosting account. Using the following script to restore. RESTORE DATABASE [XYZ] FROM DISK = N'E:\Online Website Backup\_db_backups\XYZ.bak' WITH FILE = 1, MOVE N'XYZ' TO N'C:\Program Files (x86)\Microsoft SQL Server\MSSQL.1\MSSQL\DATA\XYZ.mdf', MOVE N'XYZ_log' TO N'C:\Program Files (x86)\Microsoft SQL ...

Select Timeout With 2 Parameters

I've got the following View, called ViewGoods: SELECT G.Gid, SI.[$Id] AS FirstSiteInId, SI.Date AS FirstSiteInDate, SI.Comments AS FirstSiteInComments, S.[$Id] AS FirstSiteId, S.[$Refex] AS FirstSiteRefex, SI.Client AS ClientId, C.[$Refex] AS ClientRefex, CASE WHEN SI.Contract IS NULL THEN (SELECT Contract.[$Id] ...

How to fetch entries starting with the given string from a SQL Server database?

Hi I have a database with a lot of words to be used in a tag system. I have created the necessary code for an autocomplete box, but I am not sure of how to fetch the matching entries from the database in the most efficient way. I know of the LIKE command, but it seems to me that it is more of an EQUAL command. I get only the words that...

Can I retrieve a value from a previous line using CURSORs of SQL?

I'm developing a query, where I need that a certain field of my current line be the result of "the field of my current line" + "the same field of the previous line". (SQL Server 2008) How can I do it by using cursors? ...

Datetime pattern for yyyy.mm.dd.hh.mm.ss pattern code?

What is the DATE FORMAT CODE for "yyyy.mm.dd.hh.mm.ss"? I know that 34 (date format code) is "yyyymmddhhmmss", but what about the code for "yyyy.mm.dd.hh.mm.ss"? This is on SQL 2005. ...

Storing Data from Forms without creating 100's of tables: ASP.NET and SQL Server

Let me first describe the situation. We host many Alumni events over the course of each year and provide online registration forms for each event. There is a large chunk of data that is common for each event: An Event with dates, times, managers, internal billing info, etc. A Registration record with info about the payment and total a...

How to get the xml-safe version of an sql server XML Column

Is there a way to get the xml-safe version of an xml column in sql server ? By xml-Safe i mean escaping special characters like <,>,', &, etc. I'd like to avoid doing the replacements myself. Is there a build in function in sql server. What I want to achieve is to store the xml content into another xml attribute. ...

How to add SQLFileStream docs to content locations for MSS (MS search server)?

Hi guys, we use MS Search Server Express to search for files stored in traditional directories on our network but would like to also be able to return files that have been stored directly in SQL Server as either SQLFileStream datatype, or stored in-row as varbinary(max). How can add a SQL Server database/table/field as a content location...

SQL Server performance deterioration

I'm currently dealing with performance/memory consumption optimizations of our application. One of the tasks to perform is to replace all blobs in the a table that correspond to empty arrays with null values; this should reduce db size, memory consumption and speed up the load. Here is the table definition: CREATE TABLE [dbo].[SampleTab...

SQL Type-casting

I'm dividing some integers x & y in MS SQL, and I wan the result to be in a floating-point form. 5/2 should equal 2.5. When I simply do SELECT 5/2 I get 2, which doesn't suprise me, since it's creating an int from two ints. I know I can force it to a float by doing: SELECT CAST(5 AS FLOAT)/CAST(2 AS FLOAT); but that seems like ...

Format Table Variable Output with FOR XML AUTO

Using SQL Server 2008. I have a table variable with a single column and single row. If I do this: Declare @testsToRun Table ( testsId BigInt ) Insert Into @testsToRun Select testsId From tests Where testsId = 10 Select Top 1 * From @testsToRun For Xml Auto , Type , Root('testMessage') I get XML that looks like this: <testMessage>...

Is there a practical way to use the hierarchyID datatype in entity framework 4?

As it stands now, the CLR UDTs including HierarchyID aren't supported in Entity Framework 4. HierarchyID.ToString() is useful, but breaks down once any item has 10+ siblings (the basic structure is /3/4/12/ or /3/4/2/ so the 12th node will sort before the 2nd node). A little more about potential options: Bring back hierarchyID as ...

Trace a Hierarchy in a Table

Hi I have an "Employee" table with an "EmployeeID" column and a column representing Employee's Boss (BossID) which in turn is an employee in the "Employee" table. How can I trace the hierarchy from a given "EmployeeID" to the top most Boss. I do not want a self join approach in this, also I am using SQL Server 2005. Thank you Man...

Using LDAP Server on top of our database to allow iPhone / Blackberry Access

We have ASP.NET contact database running on SQL Server. We're not interested in syncing contacts (for a variety of reasons), but exploring using the LDAP connectors in the iPhone/Blackberry to allow users to see their database contacts on their mobile devices. Is this idea feasible? I've never played around with LDAP before... Are ther...

PHP with SQL Server: strtotime() with SQL Server DATETIME column

So I have SQL Server datetime field, and in PHP I want to use this as a UNIX TIMESTAMP, because I want to use it with strtotime, in order to add 14 days into it. Eg. If it is stored in the SQL Server database as: 2010-07-27 13:12:22.040 I want to add 14 days into it to become 2010-08-10 13:12:22.040 How would I do that using PHP wi...

Is there some way for me to generate SQL Scripts from an already existing database?

Say I already created my database but forgot to save the sql commands do create it. How could I reverse engineer the code from an already existing database? I'm using Microsoft SQL Server Express 2008. ...