sql-server-2005

XML question in SQL Server

In one of my sql scripts, I need to execute a stored procedure with the following xml string <Collection xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"&gt; <Field> <Attributes> <Attribute Name="CODE1" IsRequired="true" Order="1" IsVisible="true"/> <Attribute Name="...

How to detect if a stored procedure already exists

I have to write a deployment script which will work if a stored procedure exists or does not exist. i.e. if it exists, then I need to alter it, otherwise create it. How can I do this in the sql. I am using SQL Server 2005 ...

Export data from table to excel column name

How can I export data from table to excel with column name. ...

How to display user databases only in sqlserver?

Hi how to display user databases in sqlserver i queried as select sys.databases it displays all including msdb temp and all. i need only user cretaed databases. is there any query like : select * from sys.databases where type='u' ?? Help me. Thanks in Advance ...

How to retrieve the datetime when one row was inserted/updated in Sql Server 2005?

Hi, Is there a way to find out that info? Maybe in some kind of internal log in Sql Server? I need to generate a report based on historical data, but I haven't implemented that feature in my app, as it was not a requirement in the past. Now I'm stuck. Thanks ...

Fastest SQL 2005 select query for ASP .NET table paging ?

What is the fastest way to select a range of rows, let's say from 4.200.000 to 4.200.050, using SQL 2005? Suppose that I have 10 millions of rows. On my own projects I use the following approach, but I'm not sure if this is the best practice select * from ( select Column1, Column2, Column3 RowNumber = row_number() over (order by ...

Reclaim space in SQL 2005 table after changing datatype?

I inhereited a database with tables with many nvarchar columns. The tables were getting fairly large, and I decided to change the datatypes to varchar to cut storage because we do not use international characters. The "data space" on the table (Right-click, then "Properties") has not changed. However, if I copy this table into a new tabl...

How do I use a transaction in LINQ to SQL using stored procedures?

I have a piece of code that looks something like this (ClearImportTable and InsertPage are stored procedures): datacontext.ClearImportTable() //Essentially a DELETE FROM table for (int i = 1; i < MAX_PAGES; ++i){ datacontext.InsertPage(i); //Inserts data into the table } This is a somewhat simplified version of my code, but the id...

To Find the registry of SQL Server 2005 Management Studio

hi all.. i want the registry value SQL Server 2005 Management Studio (because our application is dependent;) before installing our application i am checking whether SQL Server 2005 Management Studio is present or not and i have cross checked that for SQL Server Management Studio with Express Edition it is having different registry value...

How do you access data that has been inserted using a ADO.NET transaction?

I'm trying to get the data that has been successfully input into the database via ADO.NET transaction. Once you've called trans.Commit() there doesn't seem to be a way of getting back the data that has been committed since all identity columns that were created during the transaction are 'virtual' since it is an offline dataset until co...

Multipurposing a failover server?

I'm not a DBA so this may be a stupid question but I'll ask it anyway. We're upgrading our SQL Servers from 2000 to 2005 and we will probably use either database replication or database mirroring. Our DBA would like to "multipurpose" the standby server meaning that he'd like to increase our capabilities and capacity by running other da...

How to deploy SQL and attach DB: With ClickOnce?

I need to deploy a winform app that uses multiple db's. I need to deploy them with my app as they interact locally. Can I use ClickOnce or should I be considering a different approach? I found a couple of examples for ClickOnce but they all assumed that the DB is included in the Solution, which isn't the case here. THis app used ...

How can I fix this SQL error on this query

DECLARE @providerIdList varchar(400) DECLARE @q varchar(400) SELECT @q = '' SELECT @providerIdList = '(1, 5, 15)' SET @q = 'SELECT u.Id FROM [user] u LEFT JOIN Provider p ON u.Provider_FK = p.Id LEFT JOIN Providers2Users pu ON pu.user_FK = u.Id LEFT JOIN Provider ap ON ap.Id = pu.provider_fk WHERE p.Id IN ' + @pr...

Breaking up SQL script

I am writing a rather long SQL script that is running close to 2000 lines of code. Since it becomes really difficult to comprehend a long script, I would like to break it up into logical units and separate them out in other SQL files. What would be the best way of doing this? Would each logical unit need to be a Stored procedure? maybe ...

Extract Unique Pairs from Table Containing Reciprocal Relationships

Consider a SQL Server 2005 database with a bunch of data on a lot of people, a large chunk of whom are married. To track relationships among people, a Relationship table exists that serves to link the ID of one person to the ID of another. A Relationship Type on each Relationship record serves to indicates the type of relationship exists...

SQL Server 2005: Call a stored procedure from a WHERE clause

I need to make a SELECT with a call of a stored procedure in the WHERE clause. It should be something like that.... SELECT distinct top 10 i.x, d.droit FROM v_droit d, v_info i WHERE d.nomdroit='yy' AND i.id<>2 AND (select val from (exec up_droits(i.x, d.droit)) <>3 But it does not work... Any idea? Don't say to replace t...

Creating SQL Server Stored Procedure from Access 2007 - change schema

I have an Access 2007 Project with a SQL Server 2005 backend. However, when creating a new stored procedure from within Access, it comes up with an error: ADO error: The specific schema name DOMAIN\username either does not exist or you do not have permission to use it How can you create a stored procedure using the 'dbo' schema ins...

Distinct on each column

I need to select 3 columns from a table, but I need each value from any column to be unique in the resultset for this column. This query: SELECT DISTINCT TOP 10 a, b, c FROM x will return 10 distinct sets. How do I do it? ...

Is any body using sql service broker to update winforms(WPF) GUI?

Hi All, I have a scenario to update Winforms application GUI when ever there is a data change in database table.Is any body using SQL Service broker to do same? For example: I have a customer and order tables in SQl Server 2005 database and I have winform(WPF) application which resides on Call Center executives(say CCE-A,CCE-B,CCE-C,...

how to using smo library in c++

Hi I am trying to list all the instances of sqlserver using c++ in vs2005. How to do this using smo library in c++? give me code example. Thanks in advance.. ...