sql-server

DB diff between before and after, export db to txt

Hello all, I have to see a difference between 2 states of the same DB (MS SQL 2008). Profiler is not an option as it is run-time tool and needs operator actions. I have not found tools for this purpose, so the question is - is there a way to export DB data into human-readable text format to compare them with something like windiff? Re...

Stored proc to remove records older than N days

I want to create a two stored procedures that will remove records older than N days from a stgging database. Both stored proc will call in a package to cleanup data older than N days. Stored proc A will remove records from table A.Fullimport & stored proc B will remove records from table B.weeklyimport. The same stored proc will remov...

How to store a string in image type column in SQL Server Using SqlParameter

I have a SQL Server database, and I want to store in image type column some string. I'm trying to do the following : SqlParameter myparam = new SqlParameter("@myparam", "VeryLongString"); myparam.SqlDbType = SqlDbType.Image; when I add it to the command and then execute it, I get the following error : Failed to convert paramete...

Why UPDATE blocks SELECT on unrelated rows?

Having the table, defined by script [1], I execute scripts in 2 windows of SSMS --1) first in first SSMS window set transaction isolation level READ UNCOMMITTED; begin transaction; update aaa set Name ='bbb' where id=1; -- results in "(1 row(s) affected)" --rollback and after 1) --2)after launching 1) select * from aaa --de...

Convert tables with "id,attribute,value" columns to "id,attribute1,attribute2,..."

Hello, I've got a table in database that looks like this: CustomerId Attribute Value ================================ 30 Name John 30 Surname Smith 30 Phone 555123456 to make some use of the data I need to make it look sth. like this: CustomerId Name Surname Phone =...

Stored procedure executes slowly on first run

Hi all, Have created a stored procedure which is utilised for monitoring purposes of a website. On first run the procedure takes over a minute to execute and if run shortly after this it takes only a few seconds to run. The problem is that the script is scheduled to run at ten minute intervals and each time it runs, it takes over a mi...

SQL Server performance difference with single or multi column primary key?

Is there any difference in performance (in terms of inserting/updating & querying) a table if the primary key is a single column (e.g., a GUID generated for every row) or multiple columns (e.g., a foreign key GUID + an offset number)? I would assume querying speeds should be quicker if anything with multi-column primary keys, however I ...

Microsoft Sync 2.1 : Oracle 11g -> SQL Server 2008 Sync : Cast not valid Exception

I am trying to sync tables in a Oracle 11g and Sql Sever 2008 databases using the Sync Framework. I used the Database Sync: Oracle and SQL Compact 2-Tier Sample as a base and was able to extend it to sync data between the Oracle 11g and Sql Server database using the same order and order_details tables. I used ODP.NET data access libra...

Coding for an SQL server in a local project

I'm coding in ASP.Net on a local machine through visual studio. So when I run the code it starts an ASP.Net service for me. So now I'm wondering how I setup an SQL server for local development purposes? I need it to have data in it constantly so that when I stop running the ASP page it doesn't just empty. ...

Convert datetime in sql server....

How can i convert the datetime format below 2010-10-25 11:13:36.700 into 25-Oct-2010 or 2010-10-25 00:00:00.000 ...

SQL Server Count of

I am trying to retrieve a count of orders for each order type (OrderTypeID) and a count of orders for each order type of distinct products (productID) eg: OrderID, OrderTypeID, ProductID 1, 1, 1 2, 1, 6 3, 2, 6 4, 1, 1 5, 2, 6 6, 2, 6 7, 2, 6 8, 3, 1 Result: OrderTypeID, Count1, Count2 1, 3, 2 2, 4, 1 3, 1, 1 I am currently retriev...

trying to run sqlcmd fails, unable to establish connection?

When I try to run sqlcmd (from the cmd prompt) I get the following error: HResult 0x2, Level 16, State 1 Named Pipes Provider: Could not open a connection to SQL Server [2]. Sqlcmd: Error: Microsoft SQL Server Native Client 10.0 : A network-related or in stance-specific error has occurred while establishing a connection to SQL ...

nest dynamic case when statements in sql 2008

Hello Experts, I have the following code in .net. foreach (string key in EntityNumbers.Keys) { if (EntityNumbers[key] != null) { e = new WebServices.Entity(); e.HierarchyLevel = key; e.Number = EntityNumbers[key]; ...

Exists Count(*)

i am trying to do as below its giving syntax error please help DELETE FROM table WHERE col1 = 2 AND EXISTS ( SELECT COUNT(*) FROM table WHERE col1 = 3 ) > 2 ; i need to do a delete only if the cout is greater than 2 ...

SQL Server date_format

What is the function DATE_FORMAT in SQL Server I want to change my now date to d-m-Y h:i How to do ...

sp_generate_inserts for oracle

Most SQL developers know and use Narayana Vyas Kondreddi's sp_generate_inserts from http://vyaskn.tripod.com/code/generate_inserts.txt Is there something similar for Oracle? ...

Get item and all related tags with one query

I have the following tables structure: Item: Id, Description Tags: Id, TagName ItemXrefTag Id, TagId, ItemId What is the best way to read all the items related to some tag and all other tags, related to the items, to be able to display list of items and all the tags related to the item? If it's not clear I`...

How can I write this query?

I have this situation in a certain table: id | name 1 'Test' 2 'Test' 3 'Test' How can I make a query to select by distinct the name, but I also need the id column... even if I get the first occorrency of the element... something like, "if the name column repeats, give me the 1st record with this repetition"....

SQL Select all days in a year with 9 blank INT fields

I am trying to get all dates in a year in a SELECT statement with 9 INT fields that have a value of 0 in them. So basically I need the following: 1/1/2007 0 0 0 0 0 0 0 0 0 1/2/2007 0 0 0 0 0 0 0 0 0 1/3/2007 0 0 0 0 0 0 0 0 0 and so on and so on for a whole year. The year is always the 1/1 - 12/31 This is part of a bigger query b...

Remote Maintenance Plans in SQL Server 2008

I've set up a maintenance plan in instance #1 of SQL Server 2008. In theory, it will connect to instance #2 and back up those databases to the hard drive of instance #1. I have: Created a login on instance #2 Given that login the correct permissions needed to back-up a database (I tested it) Created a working connection in the mainte...