sql-server-2005

Deleting Multiple Nodes in Single XQuery for SQL Server

I have: a table with an xml type column (list of IDs) an xml type parameter (also list of IDs) What is the best way to remove nodes from the column that match the nodes in the parameter, while leaving any unmatched nodes untouched? e.g. declare @table table ( [column] xml ) insert @table ([column]) values ('<r><i>1</i><i>2</i>...

Is it possible to create an indexed view with SQL Server 2008 which selects from another indexed view?

Is it possible to create an indexed view with SQL Server 2008 which selects from another indexed view? create view V1 as (select 1 as abc) create view V2 as (select abc from V1 group by abc) ...

Selecting Nth Record in an SQL Query

Hi, I have an SQL Query that i'm running but I only want to select a specific row. For example lets say my query was: Select * from Comments Lets say this returns 10 rows, I only want to select the 8th record returned by this query. I know I can do: Select Top 5 * from Comments To get the top 5 records of that query but I only wan...

SQL Insert one row or multiple rows data?

I am working on a console application to insert data to a MS SQL Server 2005 database. I have a list of objects to be inserted. Here I use Employee class as example: List<Employee> employees; What I can do is to insert one object at time like this: foreach (Employee item in employees) { string sql = @"INSERT INTO Mytable (id, name,...

Find an object in SQL Server (cross-database)

If I've been told a table (or proc) name, but not which connected database the object is located in, is there any simple script to search for it? Maybe search somewhere in the System Databases? (I'm using SQL Server 2005) ...

ASP.NET SQL Query help required

I have a result like this from a sql query Month Day Customer Item ------------------------------------------ January 1 John Pencil January 1 Jack --- January 1 Steve Stapler January 2 John --- January 2 Jack --- January 2 Steve VisitingCard January 3 John...

How to learn stored procedures in SQL Server as a Java programmer?

What is a good way to learn to develop SQL Server(2005) stored procedures? I am primarily a java developer but need to take on SQL Server stored procedure development. I have some basic SQL in my background but nothing major. Any good specific tutorials maybe using the adventure works schema? Or just good reference sites that contain alo...

Test-First development tool for SQL Server 2005?

For several years I have been using a testing tool called qmTest that allows me to do test-driven database development for some Firebird databases. I write a test for a new feature (table, trigger, stored procedure, etc.) until it fails, then modify the database until the test passes. If necessary, I do more work on the test until it f...

What is a stored procedure with a padlock icon in SQL 2005?

I see some stored procedures in one database I'm managing that have the regular stored proc icon, but with a little padlock next to them. The differences I see is that I can't "modify" them, and if I try to script them, it says "Text is Encrypted". Is this because these are CLR stored procedures? Are they "regular" procedures, but encry...

Column (Cost) was used in a CALC expression but is not defined in the rowset.

Keep getting this error after inserting a subdatasheet into a query and trying to show it by clicking on the + Column (Cost) was used in a CALC expression but is not defined in the rowset. What is confusing, is that there isn't even a column named 'Cost' anywhere in the database. Although there is a column that starts with 'Cost' and ...

How to list all objects of a particular database in SQL Server 2005

Hi, I'd like to list all objects of a particular database in SQL Server 2005. I created a query as shown below: select name, type_desc from sys.objects WHERE type in ( 'C', 'D', 'F', 'L', 'P', 'PK', 'RF', 'TR', 'UQ', 'V', 'X' ) union select name, type_desc from sys.indexes order by name However, this query list all objects of ALL d...

Display DataType and Size of Column from SQL Server Query Results at Runtime

Is there a way to run a query and then have SQL Server management studio or sqlcmd or something simply display the datatype and size of each column as it was received. Seems like this information must be present for the transmission of the data to occur between the server and the client. It would be very helpful to me if it could be dis...

CHECKSUM() collisions in SQL Server 2005

I've got a table of 5,651,744 rows, with a primary key made of 6 columns (int x 3, smallint, varchar(39), varchar(2)). I am looking to improve the performance with this table and another table which shares this primary key plus an additional column added but has 37m rows. In anticipation of adding a column to create the hash key, I did...

SQL Server 'FOR XML PATH' in PHP/MySQL

I have a SQL Server query that I need to convert to MySQL. I've never used SQL Server/T-SQL before, so I have no experience with FOR XML PATH. There's surprisingly little documentation on this sort of thing. If I remove the FOR XML PATH statement, MySQL returns the error "Operand should contain at least 1 column(s)." It seems like the n...

SQL Bulk Insert with FIRSTROW parameter skips the following line

Hello, I can't seem to figure out how this is happening. Here's an example of the file that I'm attempting to bulk insert into SQL server 2005: ***A NICE HEADER HERE*** 0000001234|SSNV|00013893-03JUN09 0000005678|ABCD|00013893-03JUN09 0000009112|0000|00013893-03JUN09 0000009112|0000|00013893-03JUN09 Here's my bulk insert statement: ...

Cannot insert datasheet into form (Access Project)

Following the instruction found here: Insert a datasheet into a form I get an error when trying to insert a query as a datasheet in an Access Project (SQL Server 2005 backend) The form name you entered doesn't follow Microsoft Office Access object-naming rules I selected the view View.dbo.viewname from the dropdown in 'Source Objec...

SQL Server 2005 Error, There is insufficient system memory to run this query.

Msg 701, Level 17, State 123, Line 1 There is insufficient system memory to run this query. I have a query that uses Table-Valued function. I am calling the function several times. Does this error mean I am running out of stack space? Or can I tune my SQL box memory settings to fix this? Any ideas? ...

SQL Server Profiler discrepancy

Hello, I am struggling with a strange problem using Sql Profiler. While running some performance testing scripts, I run profiler to find bottlenecks. One particular statement seems to be taking a lot of time - with CPU 1407, Reads 75668 and Duration of 175. However when I run the same statement in Management Studio, SQL Profiler return...

Why would I get this error intermittently? "The server was not found or was not accessible"

We keep getting this error randomly in our web application. System.Data.SqlClient.SqlException: A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured t...

Shrinking the transaction log of a mirrored SQL Server 2005 database

I've been looking all over the internet and I can't find an acceptable solution to my problem, I'm wondering if there even is a solution without a compromise... I'm not a DBA, but I'm a one man team working on a huge web site with no extra funding for extra bodies, so I'm doing the best I can. Our backup plan sucks, and I'm having a re...