sql-server-2008

counting number of rows while skipping some based on columns

I have a table in SQL Server 2008 that looks kind of like this: ID I1 I2 ... IN ------------------------- 1 2 3 ..... 2 2 0 0 ..... 0 3 2 1 ..... 5 Where IN is about 9 columns. What I need to do is count the number of rows, but skipping rows where the values of I1..IN are 0's. I'm new to SQL and I have basically...

SQL Database dilemma : Optimize for Querying or Writing?

I'm working on a personal project (Search engine) and have a bit of a dilemma. At the moment it is optimized for writing data to the search index and significantly slow for search queries. The DTA (Database Engine Tuning Adviser) recommends adding a couple of Indexed views inorder to speed up search queries. But this is to the detrimen...

Save and get arbitrary sort order in SQL Server

My client wants to sort products by drag & drop. The drag & drop part is easy with javascript. My problem is how do I save and get the sort order? I'm using .net c# and SQL Server 2008. When I move a product and drop it in a new position I get the id of the product that's moved, product in front and product behind. With this data I ...

Persisting a valid Geometry shape into Sql Server 2008 Geography column

I am using Spatial.NHibernate to save some geometry shapes to a Geography column in Sql Server 2008. Here is my mapping: public class AreaMapping : ClassMap<Area> { public AreaMapping() { Id(c => c.Id).GeneratedBy.HiLo(100.ToString()); Map(c => c.Name).Not.Nullable(); Map(x => x.Boundary) .Cus...

sql server authentication user

very basic question. sql server 2008, created new login and gave it sql authentication mode. checked status is enabled. Tried to connect to same server instance, login failed. What is going wrong? thanks for help in advance ...

How can I query the list of FULL table names in SQL server database

I have a need to iterate over all of the tables in my database. I am doing so with thsi query: SELECT so.name, so.* FROM sysobjects so WHERE so.xtype = 'U' This works fine for all of the tables in the 'dbo' schema, but it doesn't work for any other schemas. I want the output to be like this: Users.Address Users.TelephoneNumbers dbo...

SQL Server 2005->2008 upgrade: detach/attach vs. backup/restore?

There was a similar thread on this earlier, but my question is specific to upgrading from SQL2005 to 2008: when upgrading in-place is not possible because the machine has to be re-imaged, which method is preferrable - detaching and re-attaching the db files, or backup/restore? Detach/attach is obviously faster and accoding to msdn possi...

Update Collation of all fields in database on the fly

We recently moved our database from our SQL Server 2005 server to our SQL Server 2008 server. Everything moved over fine, however now we are finding that we are getting collation conflicts. The old server had a different collation with the new server. Now our tables created before the move are one collation, and the ones created after...

How to implement recursive deletion?

I have the following situation: Customers contain projects and projects contain licenses. Good because of archiving we won't delete anything but we use the IsDeleted instead. Otherweise I could have used the cascade deletion. Owkay I work with the repository pattern so I call customerRepository.Delete(customer); But here starts the...

Problem connecting to SQL db from web app (Win7 x64 host)

Hello, I am have a Silverlight app that connects to a local SQL Server db. It works as expected on my WinXP computer, but not on the Win7 x64 computer. (SQL Server 2008 installed.) When I run the app, I get this error: The remote server returned an error: NotFound. My web.config, AppSettings: <!-- For Development --> <!--<add k...

SQL Server: Rethrow exception with the original exception number

I am using a TRY CATCH block in a stored procedure where I have two INSERT instructions. If something goes wrong, the CATCH block takes care of rolling back all changes made and it works fine, except one thing! The exception caught by my ASP.NET application is a SqlException with number 50000. This is not the original number! (the numb...

Application Unable To Connect to SQL Server 2008

Hello, I've been running an ASP.NET MVC application on my IIS 7.5 localhost (on my Win7 Pro box) server with SQL Server 2005 Developer Edition. I went to put the application on my production server (IIS 7, SQL Server 2008) and am getting SQL Server connection errors. Here is the error I get when I try to browse site root: A network-...

Secure access between IIS and SQL Server.

The environment setup has an ASP.NET webservice on IIS 6 connecting to a SQL Server over the network. I am trying to understand, whether it's possible to secure the calls between IIS and SQL Server 2008. Is it possible? Is it something on the lines of SSL? thanks for reading! ...

Parameter not passed

hi.. today i fot one error. i am not able to understand why it is. i hope somebody will help me here my method is public UserFamilyInfoBO GetUserFamilyInfo(Int64 UserId) { try { DataSet Ds = new DataSet(); SqlCommand Cmd = new SqlCommand("GetUserFamilyInfo", Cn); ...

Query to get the duration and details from a table

Hi: I have a scenario and not quite sure how to query it. As a sample, I have following table structure and want to get the history of the action for bus: ID-----TIME---------BUSID----OPID----MOVING----STOPPED----PARKED----COUNT 1------10:10:10-----101------1101-----1---------0----------0---------15 2------10:10:11-----102------1102--...

TransactionScope question - how can I keep the DTC from getting involved in this?

(I know the circumstances surrounding the DTC and promoting a transaction can be a bit mysterious to those of us not in the know, but let me show you how my company is doing things, and if you can tell me why the DTC is getting involved, and if possible, what I can do to avoid it, I'd be grateful.) I have code running on an ASP.Net webs...

Sequential NEWID()

Hi, I am using sql server 2008. Is there a way to generate a unique sequential number? It should exhibit properties of NEWID() and an identity column, meaning that it is always unique but each subsequent value is greater than the previous one. It can't be datetime/datetime2, because it is not unique enough. Thanks. ...

Using SQL Express edition commercially

Can I use SQL Server Express edition for commercial use? Can our clients redistribute SQL Server Express edition with their application? ...

SQL query to list all dependant entities.

A SQL table has 100s of tables, SPs and functions. I am trying to put together a sql query that will return all the dependencies of a given set of tables. Is there a way to accomplish this using SSMS without writing queries? Updated: Simplified the question to the point. ...

Unique date range fields in SQL Server 2008

I have a table that consists of, among other things, two fields named StartTime and EndTime. Both are TIME fields. I want to add a constraint preventing the insertion of any records that overlap with preexisting time ranges. E.g. if a record already exists with StartTime = 5:00, EndTime = 10:00, I would want an insert with StartTime = 6...